在 ASP.NET 网站中保护 Elmah 的安全

发布于 2024-07-30 00:09:42 字数 1074 浏览 2 评论 0原文

我在保护 ELMAH 时遇到了麻烦。 我关注了 Phil Haacked 的 教程,唯一的区别是演示项目是一个 Web 应用程序,而我的项目是一个网站。

   <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>

使用前导“/”,我收到“找不到资源。”的响应,如果我删除前导“/”,一切正常,除了可以通过在 /admin/elmah.axd 前面附加目录名称来绕过身份验证之外。

例如,没有前导“/”

www.mysite.com/admin/elmah.axd - 触发身份验证
www.mysite.com/asdasdasd/admin/elmah.axd - 不触发身份验证并显示 ELMAH

如何确保 ELMAH 安全,同时保持远程查看日志的能力?

谢谢。

其他人请注意:
遵循下面艾伦的回答会产生以下结果。

www.mysite.com/admin/elmah.axd - 触发身份验证
www.mysite.com/admin/asdasdasd/elmah.axd - 触发身份验证
www.mysite.com/asdasdasd/admin/elmah.axd - 找不到资源。 (正是我们想要的)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲欢浪云 2024-08-06 00:09:49

我花了一些时间试图通过将每个答案中的各种建议拼凑在一起来使其发挥作用,我已经整理出了一个完整的解决方案,该解决方案应该适用于所有类型的 IIS。

以下是每个 web.config 部分中需要包含的内容:

<configuration>
  <configSections>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  </configSections>

  <elmah>
    <!-- set allowRemoteAccess="0" for extra security -->
    <security allowRemoteAccess="1"/>
  </elmah>

  <system.web>
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
  </system.webServer>

  <location path="admin">
    <system.web>
      <authorization>
        <!--<allow users="Admin" /> -->
        <deny users="?" />
      </authorization>
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <handlers>
        <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>

</configuration>

如果您使用的是 Asp.Net MVC,请添加

routes.IgnoreRoute("admin/elmah.axd/{*pathInfo}");

您的 RegisterRoutes 方法。

Having spent a while trying to get this to work by patching together the various bits of advice from each of the answers, I've put together a complete solution that should work for all flavours of IIS.

Here's what needs to be in each of your web.config sections:

<configuration>
  <configSections>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  </configSections>

  <elmah>
    <!-- set allowRemoteAccess="0" for extra security -->
    <security allowRemoteAccess="1"/>
  </elmah>

  <system.web>
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
  </system.webServer>

  <location path="admin">
    <system.web>
      <authorization>
        <!--<allow users="Admin" /> -->
        <deny users="?" />
      </authorization>
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <handlers>
        <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>

</configuration>

And if you're using Asp.Net MVC, add

routes.IgnoreRoute("admin/elmah.axd/{*pathInfo}");

in your RegisterRoutes method.

听你说爱我 2024-08-06 00:09:49

在 IIS 7.5 windows server 2008 中,还有另一个名为 system.webServer 的部分。
为了让 ELMAH 工作,必须添加以下内容:

<system.webServer>
  <handlers>
   <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> 
  </handlers>
</system.webServer>

我尝试了一些变化,但我无法使用上述解决方案来防止
'/blah/elmah.axd' 停止工作。

关于使上述解决方案适用于 IIS 7.x 有什么建议吗?

谢谢。

In IIS 7.5 windows server 2008, there is another section called system.webServer.
In order for ELMAH to work, this had to be added:

<system.webServer>
  <handlers>
   <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> 
  </handlers>
</system.webServer>

I've tried a few variances, but I am unable to use the above solution for preventing
'/blah/elmah.axd' from working.

Any Suggestions on making the above solution work for IIS 7.x?

Thanks.

安人多梦 2024-08-06 00:09:47

如果您使用 ASP.NET MVC,则需要让路由引擎忽略该路径。 例如,如果您想将 elmah 移动到 /admin/elmah.axd,您应该将以下内容添加到 Global.asax.cs:

routes.IgnoreRoute("admin/elmah.axd/{*pathInfo}");

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}");
鹤舞 2024-08-06 00:09:46

我尝试了 web.config 并得到了以下内容。 基本上,不要将 elmah.axd HttpHandler 放在通用 system.web 中,而是将其专门添加到“admin”路径位置的 system.web 中。

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文