【问题标题】:Enable Strict transport security mvc启用严格的传输安全 mvc
【发布时间】:2017-12-08 07:18:44
【问题描述】:

我想启用严格的传输安全性。 我的网站是一个 https 启用。 下面是我启用 hsts 的代码。

<system.webServer>
    <httpProtocol>
      <customHeaders>
     
          <add name="X-Frame-Options" value="SAMEORIGIN" />
          **<add name="Strict-Transport-Security" value="max-age=31536000"/>**
         .....
        </customHeaders>
    </httpProtocol>

以上设置足以启用严格的传输安全性还是我还需要添加以下设置。

<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> 

如果这两个设置都是强制性的,那么重写的需要是什么 我们只能通过启用 hsts 或仅 重写。

为什么需要重写。

This site 说要添加 rewrite alogn with

&lt;add name="Strict-Transport-Security" value="max-age=31536000"/&gt;

【问题讨论】:

    标签: asp.net-mvc security iis-7


    【解决方案1】:

    此标头强制浏览器使用 HTTPS。如果应用程序在某处给出了 HTTP 链接,或者如果用户尝试使用 HTTP 输入 URL,浏览器会将他重定向到 https。要使用 HSTS,站点需要有效的 SSL 证书。重写不是强制性的,但它很好。因为,如果用户第一次使用 https 进入网站,那么每当他来到该网站时,用户将被自动重定向,直到过期,每次访问的最大年龄也会更新。但是如果用户在http模式下进入一次,STS可能无法工作,直到他在https中使用该站点一次。最好使用重写。

    <system.webServer>
    <httpProtocol>
    <customHeaders>
    <add name=”Strict-Transport-Security” value=”max-age=xxxxxx”/>
    </customHeaders>
    </httpProtocol>
    </system.webServer>
    

    https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security

    【讨论】:

    • 即使我不使用重写,如果我尝试使用http,它也会强制浏览器使用https,即它会自动重定向到https而不重写。
    • 不使用rewrite会怎样
    • 不重写也可以工作。我没有使用 rewrite.. 只需将上面的代码用于 sts,清除浏览器缓存,然后使用 http 输入 url,您将仅使用 http 登陆站点。它不会重定向到 https。一旦你用 https 访问 url,然后尝试输入 http 并尝试进入该站点,它将不再允许你使用 http 访问该站点。再次清除缓存并尝试http,它将允许。它只是为客户端浏览器设置的值。如果你清除缓存,它就会消失。
    • 如果你不使用rewrite,也有可能登陆http。这是在我的应用程序中观察到的相同场景。
    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 2015-10-30
    • 2012-05-24
    • 2015-09-14
    • 2021-09-16
    • 1970-01-01
    • 2022-08-24
    相关资源
    最近更新 更多