Trying to find the answer and the spec doesn't actually seem to help.
The spec for HSTS says the following about the includeSubdomains
flag:
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.
All the examples I've seen assume that the request goes to e.g. example.com
(with no subdomain specified), so returning includeSubdomains
will then make it apply to www.example.com
, api.example.com
etc. as well as to example.com
.
Two questions:
If I return an HSTS header with
includeSubdomains
to a request towww.example.com
, will it then apply towww.example.com
and all other subdomains? It sounds like it does. Does it also apply to the top-levelexample.com
?If I return the HSTS header in a request to
www.example.com
and I don't include theincludeSubdomains
flag, will the HSTS header apply only towww.example.com
, or will it also apply toexample.com
?
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?