首页 > 解决方案 > 如何验证 HSTS 在 Rails 应用程序中是否按预期工作?

问题描述

大多数文档都讨论了添加 config.force_ssl = true ,它为 Rails 应用程序提供 HSTS。那么,我怎样才能确保它按预期工作?如何测试为每个请求添加的 HSTS 标头?任何帮助深表感谢。

标签: ruby-on-railsruby-on-rails-5hsts

解决方案


使用curl -I https://your_website.domain或浏览器开发工具查看响应标头。您对Strict-Transport-Security标题感兴趣:

curl -I https://www.ssllabs.com/
HTTP/2 200
date: Fri, 23 Apr 2021 15:25:17 GMT
server: Apache
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
strict-transport-security: max-age=31536000                    <-- this one
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: 0
x-frame-options: DENY
content-type: text/html;charset=ISO-8859-1
content-language: en-US
content-length: 6587
set-cookie: ...
content-security-policy: ...

推荐阅读