HTTP 严格传输安全 (HSTS)
HTTP Strict Transport Security (HSTS)

原始链接: https://hstspreload.org/

## HTTP 严格传输安全 (HSTS) 摘要 HTTP 严格传输安全 (HSTS) 是一种 Web 安全机制,它强制浏览器仅通过 HTTPS 连接到网站,从而保护免受协议降级、cookie 劫持和浏览历史记录泄露等攻击。网站通过发送特定的 HTTP 响应头来实现 HSTS。 启用 HSTS 后,它会自动将 HTTP 请求升级到 HTTPS,并在配置的情况下将此保护扩展到子域名。建议逐步推广 HSTS,从头文件中较短的 `max-age` 值开始,并在监控问题时逐渐增加它们。 虽然 HSTS 有益,但 **HSTS 预加载**——将域名添加到浏览器的内置列表中以立即强制执行 HTTPS——通常 **不推荐**,因为它具有长期承诺,并且如果任何子域名上的 HTTPS 支持中断,可能会导致潜在的并发症。预加载需要严格的标准,包括有效的证书、从 HTTP 到 HTTPS 的重定向,以及 HSTS 头中包含 `includeSubDomains` 和 `preload` 指令的一年 `max-age` 设置。从预加载列表中删除是一个缓慢的过程。 有关详细规范,请参阅 RFC 6797。

## 黑客新闻讨论:HTTP 与 HSTS 的未来 一篇关于 HTTP 严格传输安全 (HSTS) 的帖子引发了黑客新闻的讨论,质疑为什么网站仍然在 80 端口提供服务,而浏览器越来越多地默认使用 HTTPS 并利用 HSTS。 核心争论在于消除 80 端口是否能增强安全性。虽然听起来合乎逻辑,但评论员指出 TCP 本身未经过身份验证,这意味着攻击者仍然可以拦截 80 端口的初始连接。HSTS 充当一种“粘性”机制,提醒浏览器*始终*尝试 HTTPS,以防止篡改。 几位用户强调了实际挑战:依赖严格 TLS 配置的内部服务会导致混淆,完全删除 80 端口可能会导致某些用户无法访问。 另一些人指出,即使使用 HSTS,中间人攻击仍然可能发生。 对话还涉及浏览器默认设置转向 HTTPS,从而降低了 HSTS 对普通用户的价值。 然而,HSTS 仍然对于防止针对旧浏览器的攻击以及保护免受证书错误的影响非常重要,但它也可能在需要访问过期或配置错误的证书的网站时造成可用性问题。 最终,这场讨论揭示了安全性、可用性和不断发展的网络标准之间的复杂相互作用。
相关文章

原文

HTTP Strict Transport Security (HSTS) is a mechanism for websites to instruct web browsers that the site should only be accessed over HTTPS. This mechanism works by sites sending a Strict-Transport-Security HTTP response header containing the site's policy.

HSTS is supported by most major browsers. For more details on HSTS, see RFC 6797.

When a web browser enforces a domain's HSTS policy, it will upgrade all http:// URLs for that domain to HTTPS. If the policy also sets includeSubDomains, it will do this for all subdomains as well.

A site that enables HSTS helps protect its users from the following attacks done by an on-path attacker:

  • Browsing history leaks: If a user clicks on an HTTP link to a site, an on-path network observer can see that URL. If the site has an HSTS policy that is enforced, the browser upgrades that URL to HTTPS and the path is not visible to the network observer.
  • Protocol downgrades: If a site redirects from HTTP to HTTPS, an on-path network attacker can intercept and re-write the redirect to keep the browser using plaintext HTTP.
  • Cookie hijacking: On HTTP requests, an on-path network attacker can see and modify cookies. Even if the site redirects to HTTPS, the on-path attacker can inject cookies into the redirect response.

If your site is committed to HTTPS and you want browsers to enforce that your page is loaded only over HTTPS, we suggest the following steps to enable HSTS:

  1. Examine all subdomains (and nested subdomains) of your site and make sure that they work properly over HTTPS.
    • Note: This also includes internal subdomains that are not publicly accessible.
  2. Add the Strict-Transport-Security header to all HTTPS responses and ramp up the max-age in stages, using the following header values:
    • 5 minutes:
    • 1 week:
    • 1 month:
    During each stage, check for broken pages and monitor your site's metrics (e.g. traffic, revenue). Fix any problems that come up and then wait the full max-age of the stage before you move on. For example, wait a month in the last stage.

If you have a group of employees or users who can beta test the deployment, consider trying the first few ramp-up stages on those users. Then make sure to go through all stages for all users, starting over from the beginning.

Consult the Mozilla Web Security guidelines and the Google Web Fundamentals pages on security for more concrete advice about HTTPS deployment.

Since sites tell the browser that they support HSTS when the browser visits, the browser cannot know a site's HSTS policy before the user has visited the site for the first time. As a result, the browser can not require HTTPS until after the first time it has connected to the site, possibly leaving the user unprotected. After this first load, the web browser has the site's HSTS policy and is able to require HTTPS for all subsequent loads.

To account for this first-load problem, Chrome maintains a list of domains that have a strong HSTS policy and are HTTPS only. This HSTS preload list is built into Chrome. Requests to these domains will only be made over HTTPS; any HTTP requests will be upgraded to HTTPS and fail to connect if HTTPS is unavailable. Other major browsers (Firefox, Safari, IE 11 and Edge) also have HSTS preload lists based on the Chrome list.

Many browsers (Chrome, Safari) will automatically upgrade all HTTP navigations to HTTPS, regardless of the domain's HSTS policy. HSTS preloading only provides value when these upgrades fail in the presence of an active attacker. The benefits provided by HSTS preloading are minimal compared to the benefits provided by HSTS. While HSTS is recommended, HSTS preloading is not recommended.

If a site sends the preload directive in an HSTS header, it is considered to be requesting inclusion in the preload list and may be submitted via the form on this site.

In order to be accepted to the HSTS preload list through this form, your site must satisfy the following set of requirements:

  1. Serve a valid certificate.
  2. Redirect from HTTP to HTTPS on the same host, if you are listening on port 80.
  3. Serve all subdomains over HTTPS.
    • In particular, you must support HTTPS for the www subdomain if a DNS record for that subdomain exists.
    • Note: HSTS preloading applies to all subdomains, including internal subdomains that are not publicly accessible.
  4. Serve an HSTS header on the base domain for HTTPS requests:
    • The max-age must be at least 31536000 seconds (1 year).
    • The includeSubDomains directive must be specified.
    • The preload directive must be specified.
    • If you are serving an additional redirect from your HTTPS site, that redirect must still have the HSTS header (rather than the page it redirects to).

For more details on HSTS, please see RFC 6797. Here is an example of a valid HSTS header:

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

You can check the status of your request by entering the domain name again in the form above, or consult the current Chrome preload list by visiting chrome://net-internals/#hsts in your browser. Note that new entries are hardcoded into the Chrome source code and can take several months before they reach the stable version.

You must make sure your site continues to satisfy the submission requirements at all times. Note that removing the preload directive from your header will make your site immediately eligible for the removal form, and that sites may be removed automatically in the future for failing to keep up the requirements.

In particular, the requirements above apply to all domains submitted through hstspreload.org on or after October 11, 2017 (i.e. preloaded after Chrome 63)

The same requirements apply to earlier domains submitted on or after February 29, 2016 (i.e. preloaded after Chrome 50), except that the required max-age for those domains is only 10886400 seconds.

If you maintain a project that provides HTTPS configuration advice or provides an option to enable HSTS, do not include the preload directive by default. We get regular emails from site operators who tried out HSTS this way, only to find themselves on the preload list without realizing that some subdomains cannot support HTTPS. Removal tends to be slow and painful for those sites.

Projects that support or advise about HSTS and HSTS preloading should ensure that site operators understand the long-term consequences of preloading before they turn it on for a given domain. They should also be informed that they need to meet additional requirements and submit their site to hstspreload.org to ensure that it is successfully preloaded (i.e. to get the full protection of the intended configuration).

If you still wish to submit your domain for inclusion in Chrome's HSTS preload list and you have followed our deployment recommendations of slowly ramping up the max-age of your site's Strict-Transport-Security header, you can use this form to do so:

Be aware that inclusion in the preload list cannot easily be undone. Domains can be removed, but it takes months for a change to reach users with a Chrome update and we cannot make guarantees about other browsers. Don't request inclusion unless you're sure that you can support HTTPS for your entire site and all its subdomains in the long term.

However, we will generally honor requests to be removed from Chrome's preload list if you find that you have a subdomain that you cannot serve over HTTPS for strong technical or cost reasons. To request removal, please visit the removal form.

Owners of gTLDs, ccTLDs, or any other public suffix domains are welcome to preload HSTS across all their registerable domains. This ensures robust security for the whole TLD, and is much simpler than preloading each individual domain. Please contact us if you're interested, or would like to learn more.

联系我们 contact @ memedata.com