Implement HSTS (HTTP Strict Transport Security)
HSTS forces browsers 到总是 use HTTPS 为你的 site, preventing 协议 downgrade attacks 和 SSL stripping.
- 1
HSTS 是 HTTP 头: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload. 一次 browser sees 此头 遍历 HTTPS, 它将 仅 use HTTPS 为你的 site 为 max-age 第二, ignoring HTTP. 此 prevents downgrade attacks 和 SSL stripping. includeSubDomains applies 到所有 subdomains. preload allows submission 到 HSTS preload 列表 (built 为 browsers).
- 2 哈希计算器 →
HSTS 不 use 哈希 directly, 但 preload 列表 submission requires 你的 site 到是 served 遍历 HTTPS 具有有效 certificate. Verify 你的 certificate 链接是 完整和 你的 HTTPS 配置是 正确之前 enabling HSTS — 一次 browser caches HSTS, 它将 refuse HTTP connections, 和 broken HTTPS 将 make site inaccessible.
- 3 HMAC 生成器 →
为 API 认证遍历 HTTPS, use HMAC 到 sign requests. HSTS ensures 连接是 HTTPS, 和 HMAC ensures 请求是 正宗. Together 它们提供保密性 (HTTPS) 和完整性 (HMAC). 此是 常见模式为 API 安全.
常见问题
- 什么是 HSTS preload 列表?
- 列表的 domains built 为 browsers 该总是 use HTTPS, even 开第一 visit (之前 seeing HSTS 头). Submit 你的域 在 hstspreload.org. Requirements: 有效 HTTPS, HSTS 头具有 max-age ≥ 1 year, includeSubDomains, 和服务头 开根 域. 一次 preloaded, removal takes months — 不 preload 如果你 可能 need HTTP.
- 能够 HSTS 锁 users out?
- 是. 如果你的 HTTPS certificate expires 或是 misconfigured, browsers 具有 HSTS cached 将 refuse 到连接 (它们将 不 fall 回到 HTTP). 此是 为什么你 必须监控 certificate expiration 和有 automated renewal. 开始具有短 max-age (e.g., 300 第二) 为 testing, 然后 increase 到 1 year 一次 confident.