返回子域的 Strict-Transport-Security includeSubdomains

Returning Strict-Transport-Security includeSubdomains for a subdomain

试图找到答案,但规范实际上似乎没有帮助。

HSTS 规范对 includeSubdomains 标志的说明如下:

includeSubDomains is a flag which, if present, signals to the UA that
                  the HSTS Policy applies to this HSTS Server as well
                  as any subdomains of the server's FQDN.

我见过的所有示例都假定请求转到例如example.com(未指定子域),因此 returning includeSubdomains 将使其适用于 www.example.comapi.example.com 等以及 example.com.

两个问题:

  1. 如果我 return 一个带有 includeSubdomains 的 HSTS header 到 www.example.com 的请求,然后它会应用到 www.example.com所有其他子域?听起来确实如此。它也适用于 top-level example.com 吗?

  2. 如果我 return HSTS header 在对 www.example.com 的请求中并且我 包括includeSubdomains 标志,HSTS header 将 应用于 www.example.com,还是也将应用于 example.com

例如,我可以 return 一个 HSTS header 用于请求 www.example.com 和另一个 HSTS header (可能具有不同的 max-age 值)到 api.example.com?如果我 returna header 向指定了 includeSubdomainsexample.com 请求,优先级是 subdomain-specific HSTS header 还是全局 header?

If I return an HSTS header with includeSubdomains to a request to www.example.com, will it then apply to www.example.com and all other subdomains? It sounds like it does. Does it also apply to the top-level example.com?

不,它将应用于它所设置的域的所有子域。例如 sub.www.example.com。它不适用于任何同级域(例如 api.example.com),也不适用于 parent 域(example.com)。 includeSubdomains 标志用于进一步向下 - 不用于返回或横盘。

出于这个原因,许多网站建议从顶级域加载一些内容以获取顶级 HSTS 策略(s.g。https://example.com/pixel.png) and so protect the whole site including sibling domains. This works even if the request 301s to the www variant (https://example.com/pixel.png)——如果 301 包含 HSTS header, 因为这足以让浏览器看到顶级策略。

If I return the HSTS header in a request to www.example.com and I don't include the includeSubdomains flag, will the HSTS header apply only to www.example.com, or will it also apply to example.com?

www.example.com 的任何 HSTS header 对 example.com 没有影响。它仅适用于 www 域(以及可能的子域,具体取决于 includeSubdomains header 的存在)。

For instance, could I return one HSTS header for requests to www.example.com and another HSTS header (perhaps with a different max-age value) to api.example.com?

是的,他们是完全独立的。

If I returna header to requests to example.com which has includeSubdomains specified, what takes priority - the subdomain-specific HSTS header or the global header?

子域名优先。但是,如果特定于子域​​的子域在没有被重置的情况下过期,那么它就不再存在,因此基本级别的域策略就会生效。