如何禁用不需要的HTTP方法

时间:2023-03-08 21:47:01
如何禁用不需要的HTTP方法

IIS7.0默认开启了不安全的OPTIONS和TRACE方法,建议关闭这两个方法。

以下环境为windows server 2008、IIS7.0

方法(1):web.config

在<configuration>节点下添加如下代码:

<system.webServer>
<security>
<requestFiltering>
<verbs allowUnlisted="false">
<add verb="GET" allowed="true"/>
<add verb="POST" allowed="true"/>
<add verb="HEAD" allowed="true"/>
</verbs>
</requestFiltering>
</security>
</system.webServer>

以上代码只允许开启GET、POST和HEAD方法。

allowUnlisted="false":拒绝未列出的谓词。

方法(2):IIS7.0 --> “授权规则”

添加“允许”和“拒绝”规则,特定谓词只能填一个。

方法(3):IIS7.0 --> applicationHost.config

文件位置:C:\Windows\System32\inetsrv\config\

  • 若要配置 IIS 处理未列出的谓词的方式,请使用以下语法:

    appcmd set config /section:requestfiltering /verbs.allowunlisted:true | false

    例如,若要拒绝未列出的谓词,请在命令提示符处键入以下命令,然后按 Enter:

    appcmd set config /section:requestfiltering /verbs.allowunlisted:false

  • 若要配置要筛选的谓词,请使用以下语法:

    appcmd set config /section:requestfiltering /+verbs.[verb=' string ',allowed='true | false']

    变量 verb string 用于指定将应用此限制的谓词。

    例如,若要指定允许使用 GET,请在命令提示符处键入以下命令,然后按 Enter:

    appcmd set config /section:requestfiltering /+verbs.[verb='GET',allowed='true']

参考文献:

http://technet.microsoft.com/zh-cn/library/86bb183f-a016-40ca-b9c3-bbb2f5c8a4b5.aspx

http://www.iis.net/learn/manage/configuring-security/use-request-filtering

http://technet.microsoft.com/zh-cn/library/hh831621