CCyberwiki

HTTP Strict Transport Security

HTTP Strict Transport Security
TypeHTTP response header
AbbreviationHSTS
HeaderStrict-Transport-Security
SpecificationRFC 6797 (IETF, November 2012)
Directivesmax-age, includeSubDomains, and preload (outside the RFC)
CWECWE-319 (when missing)
OWASP Top 10A04:2025 Cryptographic Failures
AffectsEvery site served over HTTPS, and each of its subdomains

When a user types example.com into the address bar, the first request usually leaves the browser over plain HTTP, and the server answers with a redirect to HTTPS (see Encryption in transit). HTTP Strict Transport Security (HSTS) removes that unencrypted step for sites the browser already knows. A site sends the Strict-Transport-Security response header over HTTPS. The browser records the domain, and until the recorded time runs out it changes every http:// address for that domain to https:// before sending anything, and it stops at any TLS error on that domain instead of offering to continue.1

The redirect gap

A redirect protects a visitor only if it arrives unchanged. At Black Hat DC in February 2009, Moxie Marlinspike showed how an attacker placed between victim and site can keep the victim's side of the conversation on plain HTTP, and announced a tool for it, sslstrip, for later that month. The browser never tries an encrypted connection, so no certificate warning appears.2 From a rogue Wi-Fi access point, or by answering DNS queries in place of the real server, such an attacker can rewrite the redirect, see each path the user requests, and read or plant cookies.13 If the session cookie lacks the Secure attribute (see Cookie attributes), one plain request hands it over, which is all Session hijacking needs.1

How a browser applies the policy

Strict-Transport-Security: max-age=31536000; includeSubDomains

max-age is required and counts seconds from the moment the header arrives; 31536000 is one year. includeSubDomains is optional and takes no value.1 Each response carrying the header resets the expiry to now plus max-age, so a constant value keeps the policy alive for regular visitors.4 RFC 6797 adds these rules for the browser:1

  • The header counts only over HTTPS with no TLS fault. Over plain HTTP it is ignored, so an attacker on the path cannot add or shorten a policy.4
  • A <meta http-equiv> tag of the same name has no effect.
  • Policies belong to domain names. A host reached by its IP address is never recorded.
  • Typed addresses, links and redirects are all rewritten. An explicit port 80 becomes 443; other ports stay.
  • On a known host, any TLS problem, such as an expired, revoked or mismatched certificate, ends the connection with no way through.

The last rule is what stops interception. Suppose a user received the header above from example.com and, weeks later, opens http://login.example.com/ through a rogue access point at an airport. The browser goes to HTTPS, the attacker in the middle has no valid certificate for the name, and the user cannot click past the error.4

Subdomains and the first visit

Stored names are compared label by label from the right. A policy on example.com reaches login.example.com only if example.com sent includeSubDomains, and each host's own policy expires on its own schedule.14 If users go straight to www.example.com, a header sent only by the bare domain never reaches most of them, so it belongs on every host people enter through.1

No header protects the first request to an unknown domain. The RFC calls this the bootstrap problem and suggests a list shipped inside the browser, as root certificates are.1

The preload list

Chrome keeps such a list in its source code, and Firefox, Safari and Edge derive theirs from it. A domain qualifies when it has a valid certificate, redirects HTTP to HTTPS on the same host, serves every subdomain over HTTPS, and sends on the base domain a header with max-age of at least 31536000 plus includeSubDomains and preload.3 Whole top-level domains (the last part of a name, such as .dev) can be listed: Google added .google in 2015 and .foo and .dev from September 2017, so every name under them is HTTPS-only from the first day.5

An addition or a removal reaches users only through browser releases, which takes months, and the entry binds internal subdomains too. hstspreload.org itself advises against preloading: Chrome and Safari already try HTTPS for every navigation, and the list helps only when an attacker makes that attempt fail.3 In October 2025 Google announced that Chrome 154, due in October 2026, would turn on Always Use Secure Connections for public sites by default and ask for permission before the first visit to a public site without HTTPS.6

Misuse

Because the browser remembers one fact per domain name, the HSTS store can hold an identifier. A tracker registers 32 or more domains, loads a chosen subset over HTTPS so that each records a policy, and on a later visit requests all of them over HTTP; the ones that arrive over HTTPS spell out the visitor's number bit by bit. RFC 6797 foresaw this in its privacy section.1 In March 2018 WebKit reported that the technique was starting to be used against Safari users. Safari since accepts a policy only for the host that was loaded or its registrable domain (example.com for a.b.example.com), and ignores the upgrade for third-party loads from domains whose cookies it blocks.7

The header can also lock users out. An attacker who can inject response headers can set a policy for the victim's domain, and includeSubDomains makes any subdomain without HTTPS unreachable. A certificate left to expire on a known host has the same effect until it is replaced.1

Setting the header

hstspreload.org gives a ramp: max-age of 300 seconds, then 604800 (one week), then 2592000 (one month), each with includeSubDomains, checking for broken pages and waiting out the full value before each step up.3 To withdraw a policy, a site sends max-age=0, which browsers accept only over HTTPS.4

# nginx, in the server block that listens on 443
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Without always, nginx adds the header only to a fixed set of status codes such as 200 and 301.8 In Express, the Helmet middleware sends max-age=31536000; includeSubDomains by default and adds preload only when told to.9 On custom domains Vercel sends max-age=63072000 without includeSubDomains.10 Settings for Rails, Django and Next.js are in Securing Rails, Django and Laravel applications and Securing a Next.js and Supabase application; the other response headers are in HTTP security headers.

In SecFlash

On the Security page, SecFlash reports a missing header as SF-SEC-101, a max-age too short to last between visits as SF-SEC-102, and the missing header found during a ZAP scan as SF-SEC-624. SF-SEC-202 marks a site whose HTTP address does not redirect to HTTPS. For a zone behind Cloudflare, the Cloud page shows SF-CLD-311 when Cloudflare does not add the header.

See also

References

  1. a b c d e f g h i j Hodges, J., Jackson, C. and Barth, A. (November 2012). "HTTP Strict Transport Security (HSTS)", RFC 6797. IETF.
  2. back Lam, Jason (21 February 2009). "SSL attack announced at Blackhat DC". SANS Internet Storm Center.
  3. a b c d "HSTS Preload List Submission" (read 22 November 2026). hstspreload.org.
  4. a b c d e "Strict-Transport-Security header". MDN Web Docs. Mozilla.
  5. back McIlwain, Ben (27 September 2017). "Broadening HSTS to secure more of the Web". Google Online Security Blog.
  6. back Chrome Security (28 October 2025). "HTTPS by default". Google blog.
  7. back Fulgham, Brent (16 March 2018). "Protecting Against HSTS Abuse". WebKit blog.
  8. back "Module ngx_http_headers_module". nginx documentation.
  9. back "Helmet", README. GitHub.
  10. back "Encryption". Vercel Docs.