我是否必须为我的文档加载的所有资源(样式表、脚本、图像)返回一个HTTP Strict Transport Security header ?或者仅将它们包含在文档中就足够了吗?
安全提示应该应用于每个域,所以只要将它与文档一起发送就足以通知浏览器仅通过 HTTPS 获取资源吗?还是我误解了它的工作原理?
任何只直接访问我网站资源的人都不是我想要专门迎合的受众。
最佳答案
事实证明,发送文档的标题就足够了。
If a UA receives HTTP responses from a Known HSTS Host over a secure channel but the responses are missing the STS header field, the UA MUST continue to treat the host as a Known HSTS Host until the max-age value for the knowledge of that Known HSTS Host is reached.
https://www.rfc-editor.org/rfc/rfc6797#section-8.6
希望客户已正确实现 RFC。
更新:这是我使用的 Apache 配置。我为资源取消设置它,而不是专门为文档设置它,以确保 header 用于重定向和 Apache 生成的其他页面。
# Enable HSTS for all responses, but disable for common resources
Header always set Strict-Transport-Security "max-age=324000; includeSubDomains"
<FilesMatch "\.(css|gif|ico|jpeg|jpg|js|png|woff)$">
Header unset Strict-Transport-Security
</FilesMatch>
从每个资源的响应 header 中削减 64 个字节。
关于performance - 所有资源的 HSTS header ?或文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635065/