忽略OPTIONS请求

时间:2018-07-12 14:36:32

标签: asp.net iis web-config

我遇到的问题基本上与此相同:Blocking "System.Web.HttpException: Path 'OPTIONS' is forbidden" Errors

但是,我担心使用StaticFileHandler仍会返回标头,这些标头可能对某些在我们的应用程序中寻找漏洞的人有用。有没有一种方法可以通过忽略请求或仅返回405错误代码来解决?

1 个答案:

答案 0 :(得分:0)

-

根据评论进行了更新

如果您只是想摆脱OPTIONS请求中的日志行,则下面的方法应该有效:

<rewrite>
  <rules>
    <rule name="Ignore OPTIONS requests">
      <match url=".*"/>
      <conditions>
        <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="OPTIONS" ignoreCase="true" />
      </conditions>
      <action type="AbortRequest" />
    </rule>
  </rules>
</rewrite>

警告语-尽管以上内容确实想要您想要,但我认为这不是一个好主意。在我看来,您在管理/使用日志方面存在问题,而不是所记录的问题?

(查看Microsoft的Log Parser和/或Log Parser Studio-它免费,可编写脚本,并为您提供“类似于SQL的”语法,因此您可以通过VERB或日志文件中的任何其他数据轻松过滤掉,它将吐出表格/图形:)。

-

下面的原始帖子

看看iis中的请求过滤功能。它允许您创建允许动词的白名单,或仅明确禁止特定动词。过滤是在处理请求的早期执行的,将返回404.6错误

以下是白名单方法(仅允许GET请求,并根据需要添加其他动词)

<configuration>
 <system.webServer>
  <security>
   <requestFiltering>
    <verbsallowUnlisted="false">
     <add verb="GET" allowed="true" />
    </verbs>
   </requestFiltering>
  </security>
 </system.webServer>
</configuration>

这是更通用的版本,允许除OPTIONS

以外的所有动词
<configuration>
 <system.webServer>
  <security>
   <requestFiltering>
    <verbsallowUnlisted="true">
     <add verb="OPTIONS" allowed="false" />
    </verbs>
   </requestFiltering>
  </security>
 </system.webServer>
</configuration>

有关动词请求过滤的信息,请参阅Microsoft文档:

https://docs.microsoft.com/en-us/iis/manage/configuring-security/use-request-filtering#filter-by-verbs