【问题标题】:"RESPONSE_Strict_Transport_Security" server variable for forcing SSL in IIS用于在 IIS 中强制 SSL 的“RESPONSE_Strict_Transport_Security”服务器变量
【发布时间】:2017-07-07 12:12:06
【问题描述】:

所以,我在其他答案和其他网站中看到了此解决方案 (http://www.hanselman.com/blog/HowToEnableHTTPStrictTransportSecurityHSTSInIIS7.aspx),但我不明白如何添加 HSTS 标头。我认为这与此有很大关系:

<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />

有人能解释一下“RESPONSE_Strict_Transport_Security”的来源吗?

完整代码:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
                        redirectType="Permanent" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                    <match serverVariable="RESPONSE_Strict_Transport_Security"
                        pattern=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" value="max-age=31536000" />
                </rule>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: c# asp.net ssl iis


    【解决方案1】:

    我无法指出确切的来源,但我可以通过实验告诉你,“RESPONSE_Strict_Transport_Security”将“Strict-Transport-Security 标头添加到响应中,与“RESPONSE_Expect_Staple”添加“Expect-Staple”标头。

    以下两个链接暗示我们可以预期上述行为,但我从未找到有关其工作原理的文档。

    https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/modifying-http-response-headers

    Add custom header based on file type

    【讨论】:

      【解决方案2】:

      我想我找到了。来自"URL Rewrite Module 2.0 Configuration Reference"

      如果服务器变量以“RESPONSE_”开头,则它存储 HTTP 响应标头的内容,其名称由使用以下命名约定确定:

      1. 名称中的所有下划线 ("_") 符号都将转换为破折号 ("-")。
      2. “RESPONSE_”前缀被移除

      然后在文档中:

      URL 重写模块 2.0 中的出站重写规则可用于设置新的或修改现有的响应 HTTP 标头。通过使用与服务器变量相同的语法并使用从重写规则访问响应标头中所述的命名约定,可以在出站规则中访问响应 HTTP 标头。 ... 重写规则的模式将应用于指定响应头的内容,如果规则的模式和可选条件评估成功,则该响应头的值将被重写。

      因此,该示例中的代码表示,“如果Strict-Transport-Security 响应标头具有任何值(.*),包括未定义,则将该值重写为max-age=31536000(如果满足条件)。

      【讨论】:

      • 我认为如果标头没有任何值或根本不存在, .* 也匹配。在这种情况下,标题将由规则添加。
      • @crokusek 同意,并更新了答案以澄清。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 2020-11-01
      相关资源
      最近更新 更多