【问题标题】:IIS Removing nosniff header for imagesIIS 删除图像的 nosniff 标头
【发布时间】:2018-08-01 01:21:52
【问题描述】:

我有一个返回图像的 API,例如:

/api/products/images/233 -> 这将返回一个 233.jpg 图片

但是我的 IIS 有一条规则可以将 X-Content-Type-Options 标头添加到安全请求中,但这会破坏 Internet Explorer 上的图像,因此我需要一种方法来在端点 /products/ 时删除此规则images/ 仅在不是那个端点时才被调用或添加标头的方法。

我尝试使用这个关于Custom Headers

但是没用,我试过这样:

<system.webServer>
    <rewrite>
      <outboundRules>
        <rule name="Remove nosniff">
          <match serverVariable="RESPONSE_X_Content_Type_Options" pattern="/products/images/" />
          <action type="Rewrite" value="none"/>
        </rule>
      </outboundRules>
    </rewrite>
  </system.webServer>

但它并没有改变任何东西,图像仍然有“nosniff”标题。

我是否缺少一些配置?还是有其他方法可以做到这一点?

【问题讨论】:

    标签: iis


    【解决方案1】:

    您的匹配条件是检查标头 RESPONSE_X_Content_Type_Options 是否包含值 /products/images/ 而不是 nosniff。您可以使用位置块将此规则限制为/products/images/,然后使用pattern="nosniff" 查找值nosniff

    <configuration>
        ...
        <system.webServer/>
        ...
        <location path="products/images/">
            <system.webServer>
                <rewrite>
                    <outboundRules>
                        <rule name="Remove nosniff">
                            <match serverVariable="RESPONSE_X_Content_Type_Options" pattern="nosniff" />
                            <action type="Rewrite" value="none"/>
                        </rule>
                    </outboundRules>
                </rewrite>
            </system.webServer>
        </location>
    </configuration>
    

    有关元素,请参阅文档:https://msdn.microsoft.com/en-us/library/b6x6shw7(v=vs.100).aspx

    【讨论】:

    • 谢谢,它成功了。 Ps:我无法编辑您的答案,因为“位置路径”不允许在字符串的结尾/开头使用斜杠,所以修复是“path="products/images"。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 2011-12-18
    • 2016-05-09
    • 2013-01-06
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多