IIS:如何禁用HTTP方法TRACE?

时间:2019-02-07 21:11:46

标签: http iis web-config trace httpverbs

我关注了this,导致this试图禁止我的网站接受TRACE方法(动词)。基本上,我将以下部分添加到Web.config(默认网站和其他网站)的<system.webServer>中:

<security>
   <requestFiltering>
       <verbs applyToWebDAV="false">
          <add verb="TRACE" allowed="false" />
       </verbs>
   </requestFiltering>
</security>

它没有用。然后,我转到C:\ Windows \ System32 \ inetsrv \ config \ applicationHost.config,并替换了<handlers>中所有处理程序的动词。简而言之,所有行都是这样的:

<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />

对此表示敬意:

<add name="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />

我什至重新启动了服务器,但是当我检查可用方法时,TRACE仍然存在:

$ curl -I -X OPTIONS https://example.com/mysite
HTTP/1.1 200 OK
Allow: OPTIONS, TRACE, GET, HEAD, POST
Public: OPTIONS, TRACE, GET, HEAD, POST
X-XSS-Protection: 1; mode=block
Date: Thu, 07 Feb 2019 21:03:49 GMT
Content-Length: 0

那么,我该如何摆脱呢?

2 个答案:

答案 0 :(得分:1)

要真正阻止TRACE请求,您仍然应保留TRACE动词被阻止的请求过滤规则。

curl命令将一个OPTIONS请求发送到IIS,ProtocolSupportModule生成响应消息,

https://docs.microsoft.com/en-us/iis/get-started/introduction-to-iis/iis-modules-overview

但是,Microsoft并未在system.webServer/httpProtocol部分中为您设计任何设置来更改标题的值,以便从此处隐藏TRACE

但是一种解决方法是使用URL重写模块,

https://blogs.msdn.microsoft.com/benjaminperkins/2012/11/02/change-or-modify-a-response-header-value-using-url-rewrite/

在其中为AllowPublic标头创建两个出站规则,

<rewrite>
    <outboundRules>
        <rule name="ChangeHeaders" stopProcessing="false">
            <match serverVariable="RESPONSE_Allow" pattern="OPTIONS, TRACE, GET, HEAD, POST" />
            <action type="Rewrite" value="OPTIONS, GET, HEAD, POST" />
        </rule>
        <rule name="Public">
            <match serverVariable="RESPONSE_Public" pattern="OPTIONS, TRACE, GET, HEAD, POST" />
            <action type="Rewrite" value="OPTIONS, GET, HEAD, POST" />
        </rule>
    </outboundRules>
</rewrite>

答案 1 :(得分:1)

在我的情况下有效:

 <requestFiltering>
      <verbs allowUnlisted="false">
        <clear/>
        <add verb="GET" allowed="true" />
        <add verb="HEAD" allowed="true" />
        <add verb="POST" allowed="true" />
      </verbs>
    </requestFiltering>

请注意,我不允许使用OPTIONS。 当我不允许使用OPTIONS时,TRACE也不允许。

相关问题