use*_*166 4 security asp.net-mvc iis-7
我想实现严格的运输安全。我的网站启用了 https。下面是我启用 hsts 的代码。
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
**<add name="Strict-Transport-Security" value="max-age=31536000"/>**
.....
</customHeaders>
</httpProtocol>
Run Code Online (Sandbox Code Playgroud)
上面的设置足以启用严格的传输安全,还是我还需要添加下面的设置,即。
<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>
Run Code Online (Sandbox Code Playgroud)
如果这两个设置都是强制性的,那么我们需要重写什么,我们可以仅通过或仅通过重写来启用hsts。
为什么需要重写。
该网站说要添加重写alogn with
<add name="Strict-Transport-Security" value="max-age=31536000"/>
此标头强制浏览器使用 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>
Run Code Online (Sandbox Code Playgroud)
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
| 归档时间: |
|
| 查看次数: |
20944 次 |
| 最近记录: |