Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Securing Elmah in ASP.NET website

I am having trouble trying to secure ELMAH. I have followed Phil Haacked's tutorial, with the only difference being the demo project is a web application and my project is a website.

   <add verb="POST,GET,HEAD" path="/admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />     <location path="admin">         <system.web>               <authorization>                   <deny users="?"/>               </authorization>           </system.web>      </location> 

With the leading "/" I receive the response that "The resource cannot be found.", if I remove the leading "/" everything works fine except authentication can be bypassed by appending a directory name in front of /admin/elmah.axd.

For example without the leading "/"

www.mysite.com/admin/elmah.axd - triggers the authentication
www.mysite.com/asdasdasd/admin/elmah.axd - does not trigger the authentication and displays ELMAH

How can I ensure that ELMAH is secure while maintaining the ability to remotely view the log?

Thanks.

Note to others:
Following Alan's answer below results in the following.

www.mysite.com/admin/elmah.axd - triggers the authentication
www.mysite.com/admin/asdasdasd/elmah.axd - triggers the authentication
www.mysite.com/asdasdasd/admin/elmah.axd - The resource cannot be found. (exactly what we wanted)

like image 658
Justin Svetlik Avatar asked Aug 07 '09 15:08

Justin Svetlik


People also ask

What is ELMAH Axd?

Description. ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

How do you check ELMAH error?

Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.

Does ELMAH work with .NET core?

ELMAH doesn't support ASP.NET Core.


2 Answers

I played around with the web.config and got the following to work. Basically instead of putting the elmah.axd HttpHandler in the general system.web, add it specifically in the system.web of your "admin" path location.

<location path="admin">     <system.web>         <httpHandlers>             <add verb="POST,GET,HEAD" path="elmah.axd"                  type="Elmah.ErrorLogPageFactory, Elmah" />         </httpHandlers>         <authorization>             <deny users="?"/>         </authorization>     </system.web> </location> 
like image 126
Alan Avatar answered Sep 21 '22 04:09

Alan


If you are using ASP.NET MVC, you're going to need to have the routing engine ignore that path. If you want to move elmah to /admin/elmah.axd for instance you should add the following to Global.asax.cs:

routes.IgnoreRoute("admin/elmah.axd/{*pathInfo}"); 
like image 33
aarondcoleman Avatar answered Sep 25 '22 04:09

aarondcoleman