# HTTP严格传输安全

**HTTP严格传输安全**（HTTP Strict Transport Security，HSTS）是一种Web安全策略机制，于2012年11月标准化为RFC 6797。通过该机制，Web服务器指示浏览器在指定期限内仅通过HTTPS与其通信，升级不安全的链接，并将证书错误视为致命错误，用户无法选择忽略这些错误。<sup>[1](https://www.rfc-editor.org/info/rfc6797/)</sup> 服务器通过`Strict-Transport-Security` HTTP响应头声明该策略，且该响应头须通过安全传输发送。<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准 | RFC 6797，2012年11月发布；IETF的互联网标准跟踪文档<sup>[1](https://www.rfc-editor.org/info/rfc6797/)</sup> |
| 头部 | `Strict-Transport-Security`响应头，仅通过安全传输发送；`max-age`指令为必需，`includeSubDomains`为可选<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup> |
| 示例 | `Strict-Transport-Security: max-age=31536000; includeSubDomains; preload`对该主机及其子域强制执行HTTPS一年<sup>[3](https://.cio.gov/hsts/)</sup> |
| 预加载要求 | 要加入HSTS预加载列表，须设置`includeSubDomains`、`max-age`至少为一年（31536000秒）以及`preload`指令，并在hstspreload.org提交<sup>[4](https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/TLS)</sup> |
| 采用率（2025年） | 36%的移动端页面发送了该头部，同比增长6个百分点；2025年第三季度全球排名前1000万的网站中有31.1%采用<sup>[5](https://almanac.httparchive.org/en/2025/security)</sup><sup> • </sup><sup>[6](https://publications.jrc.ec.europa.eu/repository/bitstream/JRC143101/JRC143101_01.pdf)</sup> |
| 正确性 | 发送该头部的网站中仅22.1%通过了正确性检查；其余使用了较短的`max-age`或省略了`includeSubDomains`和`preload`<sup>[7](https://centralcsp.com/en/state-of-the-web/)</sup> |
| 已知缺口 | 对域名的首次连接不受保护，这一弱点称为“首次使用信任”，实践中通过预加载来解决<sup>[8](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/iet-ifs.2017.0030)</sup> |

## 策略的工作方式

当符合规范的浏览器（RFC术语中称为用户代理）通过安全连接收到有效的`Strict-Transport-Security`头部时，它会将该主机记录为已知HSTS主机，并在`max-age`规定的期限内，将发往该主机的每个请求在发送之前转换为HTTPS。如果无法建立安全连接，浏览器将错误视为致命错误，不向用户提供以不安全方式继续的点击通过选项。<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup>

该头部携带三个指令。必需的`max-age`给出浏览器必须将该主机视为HSTS主机的秒数；值为零时，浏览器会删除已存储的策略，运维人员即以此关闭策略。<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup> 可选的`includeSubDomains`将策略扩展到该主机名下的所有子域，使策略能够保护应用于整个子树范围的域Cookie。<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup> `preload`指令不属于RFC 6797的一部分；它表示该站点希望被编入浏览器二进制文件内置的预加载列表。<sup>[9](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)</sup>

RFC还明确了该策略不覆盖的范围。HSTS针对的是被动窃听者、主动网络攻击者和会犯错的Web开发者，但它明确不是钓鱼或恶意软件的补救措施。<sup>[2](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)</sup>

## 预加载与首次访问问题

普通HSTS存在一个结构性缺口：浏览器只有在成功完成一次HTTPS访问后才会获知策略。在首次接触时，控制网络的攻击者可以在任何头部到达之前剥离或阻断HTTPS连接。这一弱点称为“首次使用信任”（Trust On First Use），源于协议必须信任其观察到的第一个连接这一事实。<sup>[8](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/iet-ifs.2017.0030)</sup>

预加载列表填补了这一缺口。设置了`preload`并将域名提交至hstspreload.org的HSTS预加载服务的站点，会被编入使用预加载列表的浏览器二进制文件中，这一机制的使用范围不限于Chrome。<sup>[9](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)</sup> 此后，浏览器在收到来自这些站点的`Strict-Transport-Security`头部之前，就会对预加载站点执行HTTPS升级，从而防止首次使用时的降级攻击，建议高风险网站采用。<sup>[4](https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/TLS)</sup> Chrome、Firefox/Mozilla和[Safari](https://www.edgepedia.org/zh/safari-web-browser)均使用Chrome预加载列表，纳入要求`max-age`至少为12个月。<sup>[10](https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security/)</sup>

预加载被有意设计为难以逆转。通过hstspreload.org表单移除预加载，要求站点以有效证书提供HTTPS服务，并发送不带`preload`指令的有效HSTS头部，且移除可能需要6至12周才能到达大多数Chrome用户，其他浏览器所需时间更长。<sup>[11](https://hstspreload.org/removal/)</sup> 每个预加载条目还会占用浏览器二进制文件的空间，因此Chromium维护者对人工例外保持保守态度，倾向于接纳用户量大或安全敏感的服务（如银行和健康类网站）。<sup>[12](https://github.com/chromium/hstspreload.org/wiki/Preload-List-Processes)</sup>

## 部署指导

由于HSTS策略会在`max-age`秒内被缓存，草率推出可能导致用户无法访问站点。任何需要非加密HTTP连接的功能在`max-age`设定的期限内实际上都会失效，如果应用了`preload`，失效时间可能更长。<sup>[9](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)</sup> 推荐的推出方式是分阶段进行：先使用较小的`max-age`和`includeSubDomains`但不加`preload`（`max-age=3600; includeSubDomains`），经过一周左右的冷却期后提高期限，只有在大约三个月无问题后，才以两年`max-age`添加`preload`（`max-age=63072000; includeSubDomains; preload`）并提交至预加载列表。<sup>[9](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)</sup>

## 采用率与正确性

采用率稳步增长但并不均衡。2025年Web Almanac测量到36%的移动端页面使用了HSTS头部，较上一版增长6个百分点，其中96%的发送者使用了有效的`max-age`，约40%保护了子域，仅约22%使用了`preload`。<sup>[5](https://almanac.httparchive.org/en/2025/security)</sup> 发送者中`max-age`的中位数为365天，在第90百分位处翻倍至730天，第10百分位从30天升至91天，表明设置极短策略的站点减少了。<sup>[5](https://almanac.httparchive.org/en/2025/security)</sup> 欧盟委员会联合研究中心测量到2025年第三季度全球排名前1000万的网站中采用率为31.1%。<sup>[6](https://publications.jrc.ec.europa.eu/repository/bitstream/JRC143101/JRC143101_01.pdf)</sup>

发送头部不等于发送得当。在一项2026年的测量中，三分之一的站点发送了`Strict-Transport-Security`，但其中仅22.1%通过了正确性检查，其余的使用了较短的`max-age`或省略了`includeSubDomains`和`preload`；它是广泛采用的安全头部中采用率与正确性差距最显著的一个。<sup>[7](https://centralcsp.com/en/state-of-the-web/)</sup> 采用率也与网站流行度相关：最受欢迎的站点中头部的使用率始终高于整个网络。<sup>[5](https://almanac.httparchive.org/en/2025/security)</sup> 早期研究发现了同样的模式；2015年NDSS关于HSTS和密钥固定的研究将部署描述为仅限于少数大型网站和由注重安全的小型网站构成的长尾。<sup>[13](https://www.ndss-symposium.org/ndss2015/ndss-2015-programme/upgrading-https-mid-air-empirical-study-strict-transport-security-and-key-pinning/)</sup>

## 攻击与局限

**剥离与降级攻击。** HSTS的存在是为了击败HTTPS剥离攻击，即网络上的攻击者将HTTPS链接改写为HTTP。然而，测量工作已发现残余缺陷，包括传输错误、重定向错误、字段设置错误、书签自动补全以及导航面板中的嵌入地址，并演示了一种利用这些缺陷的增强型剥离攻击。<sup>[14](https://eudl.eu/doi/10.1007/978-3-319-78813-5_25)</sup>

**时间操纵。** 由于策略在`max-age`后过期，能够移动受害者系统时钟的攻击者可以强制其过期。Jose Selvi（何塞·塞尔维）2014年的Delorean工具即以此方式使HSTS失效，利用NTP协议和操作系统更新机制中的弱点，在中间人场景中移动系统时间。<sup>[8](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/iet-ifs.2017.0030)</sup>

**跟踪。** HSTS状态独立于Cookie持久存在于浏览器中，这使得它可被用作持久的跨站标识符，通常称为HSTS超级Cookie。跟踪者为访客分配一个二进制标识符，在跟踪者控制的域名上为每个置位请求一个HTTPS子域，并将这些位缓存为HSTS策略；之后的脚本再通过HTTP加载这些子域，读回浏览器将哪些升级为了HTTPS。HSTS作者在规范第14.9节中承认了这种可能性。<sup>[15](https://webkit.org/blog/8146/protecting-against-hsts-abuse/)</sup> 在针对Safari用户的此类滥用开始部署后，Apple修改了其网络栈，仅允许已加载主机名或顶级域加一级（TLD+1）的HSTS状态，阻止了跟踪者曾使用的深子域和多兄弟域编码。<sup>[15](https://webkit.org/blog/8146/protecting-against-hsts-abuse/)</sup>

**运维锁定。** 击败攻击者的同一持久性也使错误代价高昂。如果一个域名下有无法提供HTTPS服务的子域，在该域名上错误配置`preload`可能导致用户在策略期限内无法访问这些子域，这正是分阶段推出和预加载列表自身移除要求存在的原因。<sup>[9](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)</sup><sup> • </sup><sup>[11](https://hstspreload.org/removal/)</sup>

## References

1. [RFC 6797: HTTP Strict Transport Security (HSTS), RFC Editor](https://www.rfc-editor.org/info/rfc6797/)
2. [RFC 6797 full text (PDF), RFC Editor](https://www.rfc-editor.org/rfc/pdfrfc/rfc6797.txt.pdf)
3. [The HTTPS-Only Standard: HTTP Strict Transport Security, U.S. federal CIO council](https://.cio.gov/hsts/)
4. [Transport Layer Security (TLS) configuration, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/TLS)
5. [Security, The Web Almanac 2025 by HTTP Archive](https://almanac.httparchive.org/en/2025/security)
6. [Figure 12: HSTS adoption in the top 10M websites, Q3 2025, Joint Research Centre, European Commission](https://publications.jrc.ec.europa.eu/repository/bitstream/JRC143101/JRC143101_01.pdf)
7. [State of the Web 2026: client-side security report, CentralCSP](https://centralcsp.com/en/state-of-the-web/)
8. [De los Santos et al. (2018). Analysing HSTS and HPKP implementation in both browsers and servers. IET Information Security.](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/iet-ifs.2017.0030)
9. [Use a strong HSTS policy, Lighthouse, Chrome for Developers](https://developer.chrome.com/docs/lighthouse/best-practices/has-hsts?hl=en)
10. [HTTP Strict Transport Security (HSTS), Cloudflare SSL/TLS docs](https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security/)
11. [HSTS Preload List Removal, hstspreload.org](https://hstspreload.org/removal/)
12. [Preload List Processes, chromium/hstspreload.org Wiki](https://github.com/chromium/hstspreload.org/wiki/Preload-List-Processes)
13. [Upgrading HTTPS in Mid-Air: An Empirical Study of Strict Transport Security and Key Pinning, NDSS 2015](https://www.ndss-symposium.org/ndss2015/ndss-2015-programme/upgrading-https-mid-air-empirical-study-strict-transport-security-and-key-pinning/)
14. [HSTS Measurement and an Enhanced Stripping Attack Against HTTPS, EUDL](https://eudl.eu/doi/10.1007/978-3-319-78813-5_25)
15. [Protecting Against HSTS Abuse, WebKit blog](https://webkit.org/blog/8146/protecting-against-hsts-abuse/)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › 网络防御与威胁 › TLS与传输层安全

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/http-strict-transport-security

English original: https://www.edgepedia.org/http-strict-transport-security
