IIS 设置标头并重写 3xx 响应的 url

问题描述 投票:0回答:1

经过渗透测试,他们发现

Web 服务器不提供 Content-Security-Policy 标头 带有属于 4xx 类且在 HTTP 上的状态代码的 HTTP 响应 响应的状态代码属于 3xx 类的子路径 以下网址:

对于 4xx,我创建了一个自定义页面并设置 IIS 以在以防万一的情况下使用它,但对于 3xx,我不知道如何使用 url 重写,我在 SO 和 Web 上查找,但没有找到有效的解决方案,有人可以提供帮助我举个例子?预先感谢

iis header content-security-policy iis-10
1个回答
0
投票

您可以采取以下方法:

  1. 确保在 IIS 中启用 CustomHeaders 模块。如果没有,您可以在 IIS 管理器中启用它,方法是转至服务器的功能并启用 HTTP 响应标头功能。

  2. 修改 web.config 文件以添加必要的规则和标头。

以下是如何配置 web.config 的示例:

<configuration>
 <system.webServer>
   <rewrite>
    <rules>
      <rule name="Rewrite 3xx Responses" stopProcessing="true">
        <match url=".*" />
          <conditions>
           <add input="{RESPONSE_STATUS}" pattern="^3\d\d$" />
          </conditions>
         <action type="Rewrite" url="{R:0}" />
       </rule>
     </rules>
  </rewrite>

  <!-- Custom Headers for 3xx Responses -->
  <httpProtocol>
    <customHeaders>
      <add name="Content-Security-Policy" value="default-src 'self';" />
    </customHeaders>
  </httpProtocol>
 </system.webServer>
</configuration>

URL 重写规则匹配所有 URL (url=".*"),并且仅当响应状态代码在 3xx 范围内时才适用(使用模式="^3\d\d$")。重写操作会重写 URL,确保规则得到应用和处理。customHeaders 部分确保将 Content-Security-Policy 标头添加到所有响应中,包括 3xx。

重写操作不会更改 URL,但可确保规则得到处理。 Content-Security-Policy 标头在此处全局应用,因此它将出现在 2xx 和 3xx 响应中。

© www.soinside.com 2019 - 2024. All rights reserved.