Reference
HSTS: HTTP Strict Transport Security Explained
HSTS, short for HTTP Strict Transport Security, is a response header that tells a browser to reach a site only over HTTPS for a stated number of seconds. Once the browser has seen it, typing example.com produces no plain HTTP request at all. The browser rewrites the address internally, before anything leaves the machine.
That last part is the whole point, and it is easy to miss. Plenty of sites force HTTPS with a redirect and assume the job is finished. It is not.
The one request a redirect cannot save
Say your site answers on port 80 and sends a 301 redirect to the HTTPS version. That is good practice and you should keep doing it. But look at what happens on the wire: the browser sends a request in the clear, and only then learns it should have used HTTPS. One unprotected round trip, every time someone types the bare domain or follows an old http:// link.
That request is where SSL stripping lives. Moxie Marlinspike demonstrated the attack at Black Hat DC in 2009 with a tool called sslstrip. An attacker sitting between you and the site, on café wifi or anywhere along the network path, intercepts the plain HTTP request, talks HTTPS to the real server on your behalf, and serves you a downgraded copy over HTTP. No padlock appears, and hardly anyone notices its absence. Whatever you type goes through the attacker in readable form.
HSTS deletes the request the attack depends on. With a policy cached, the browser upgrades http://example.com to https://example.com internally and sends nothing over port 80. There is no plaintext request left to intercept. The difference between HTTP and HTTPS only protects you if the browser reliably picks the second one, and this is how you make it reliable.
HSTS does a second, quieter thing. It makes certificate errors fatal. On an ordinary site you can click through a warning about an expired or mismatched certificate. On an HSTS host you cannot, because the browser refuses and offers no override. That shuts down the variant of the attack where a user is talked into accepting a bad certificate.
The header, directive by directive
The header comes from RFC 6797, published by the IETF in November 2012. In full it looks like this:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
max-age is the only required directive, and its value is a number of seconds. max-age=31536000 means “for the next year, do not talk to this host over HTTP”. The clock restarts on every response the browser sees, so an active site with a one-year policy keeps a one-year policy indefinitely. A visitor who never returns keeps theirs until it runs out.
includeSubDomains extends the policy to every host below the one that sent it. Send it from example.com and it covers www.example.com, api.example.com and anything else under that name. Send it from secure.example.com and it covers hosts below secure but not example.com itself.
preload appears nowhere in RFC 6797. It is a browser-vendor convention: a token you add to signal that you want your domain baked into the browser. On its own it does nothing whatsoever. It only matters in combination with a submission, which is the next section.
Trust on first use, and why preload exists
HSTS has a hole in it, and the hole is structural. A browser learns your policy by receiving your header, and it can only receive your header after one successful HTTPS connection. Before that it knows nothing about you. A fresh browser profile or a visitor who cleared their data gets exactly one unprotected attempt at your site, which is the attempt HSTS was meant to eliminate.
Security people call this trust on first use. The preload list is the answer to it.
The list is a set of domains compiled directly into the browser. Chrome maintains it, and Firefox, Safari and Edge build their own lists from the same source. A domain on the list is HSTS-protected from the moment the browser is installed, before it has ever heard of you. Chrome will show you both its static and dynamic entries at about://net-internals#hsts if you want to look.
Submission runs through hstspreload.org, and the requirements are checked automatically:
- A valid certificate.
- A redirect from HTTP to HTTPS on port 80, on the same host.
- HTTPS working on all subdomains, including
wwwif a DNS record for it exists. - An HSTS header on the base domain with
max-ageof at least 31536000 seconds (one year), plusincludeSubDomains, pluspreload.
Meet all of that and you can submit. Read the next section before you do.
Why HSTS is hard to undo
Vendor documentation tends to hurry past this bit. HSTS is a promise stored on other people’s computers, and you have no way to reach in and edit it once it is there.
While a policy is live in someone’s browser, that browser will not make a plain HTTP request to your domain. Suppose your certificate expires and you want to serve HTTP for an hour while you sort it out. You cannot. The browser will not connect, and the user cannot override it. There is no mechanism for pushing a retraction into a cache you do not control.
Removing a dynamic policy means serving max-age=0 over a working HTTPS connection and then waiting. Each returning visitor picks up the zero and forgets the policy. Anyone who does not come back holds the old policy until it expires by itself, which is why the max-age you chose a year ago is the deadline you are now stuck with. MDN states the constraint plainly: you cannot disable HSTS over insecure HTTP. If HTTPS is the thing that broke, you have no channel left to send the fix through.
Preload removal is worse. A removal form exists and it works, but the change only reaches users when it ships inside a browser release. Chromium’s own documentation says it takes months to reach Chrome users, and makes no guarantees whatsoever about other browsers. Your domain is in the binary, and getting it out means waiting on release trains you do not drive.
So ramp up instead of jumping in:
- Start at
max-age=300(five minutes). Deploy, then watch for anything that breaks. - Move to
max-age=86400(a day), then to a week. At each step your worst case is a short outage. - Once you are confident, go to
max-age=31536000. - Add
preloadlast, if at all, and only after months of a stable one-year policy.
If you are not sure you will still control this domain and serve it over HTTPS in five years, do not preload it.
includeSubDomains is the one that breaks things
Most HSTS incidents trace back to this directive. includeSubDomains covers every host below yours, including the ones nobody remembers: the forgotten wiki on old.example.com with a long-expired certificate, or the internal tool that only ever spoke HTTP because it lived behind the VPN. Each of them becomes unreachable in browsers the moment the policy lands, and you cannot quickly undo it.
Inventory your subdomains first, including the ones sitting in DNS that you had forgotten about. Every one needs working HTTPS before you send includeSubDomains.
One clarification, because this causes needless panic: HSTS is a rule about how browsers make HTTP requests, and nothing else obeys it. Your MX records, SMTP delivery, IMAP and any other non-HTTP service on a subdomain carry on exactly as before. It governs browsers, not ports.
The other headers worth sending
HSTS usually travels with a few other response headers. Short versions of each:
X-Content-Type-Options: nosniff stops the browser guessing at content types. Without it, a browser may inspect a response body and decide it knows better than your Content-Type, which is how a file uploaded as text/plain ends up executed as HTML. With nosniff the declared type is the type used, scripts served with a non-JavaScript MIME type are blocked outright, and stylesheets that are not text/css likewise. One value, and no downside on a correctly configured server.
X-Frame-Options: DENY (or SAMEORIGIN) stops other sites embedding your pages in a frame, which is the mechanism behind clickjacking. The frame-ancestors directive in Content-Security-Policy supersedes it in modern browsers, but the older header costs nothing to keep.
Referrer-Policy controls how much of the current URL gets sent to the sites you link out to. strict-origin-when-cross-origin is the sensible default: full URL internally, bare origin to other sites, nothing at all when the destination downgrades to HTTP.
Content-Security-Policy is the big one, and the only header here you cannot deploy blind. It declares where scripts, styles, images and frames may load from, which shuts down most cross-site scripting. It also breaks pages that quietly depend on inline scripts or third-party embeds, so run it in Content-Security-Policy-Report-Only mode first and read the reports.
Check any site’s setup
You do not have to take a site’s word for any of this, including ours. The HTTP status and redirect checker fetches any URL and reports what actually comes back: whether Strict-Transport-Security is present, its max-age in seconds and in human terms, whether includeSubDomains and preload are set, and whether the HTTP to HTTPS redirect chain works. It reports the security headers above at the same time.
Two things are worth checking on your own domain. First, that the header appears on the HTTPS response itself rather than only on the redirect, since a redirect response is the wrong place to carry it. Second, that max-age really is what you think it is. A stray digit turns one year into ten days or three decades.
What this site sends, and why
Rather than recommend what we do not do ourselves, here is our configuration:
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Content-Type-Options: nosniff
That is 180 days, all subdomains, no preload.
Six months is a real commitment. It is long enough that any returning visitor is always upgraded, and short enough that a bad situation heals itself in half the time a one-year policy would need. includeSubDomains is safe here because every subdomain we run is HTTPS-only, and there are few of them.
Preload is a deliberate omission. The extra protection it buys is narrow: it covers the single first request from a browser that has never visited before, and only when an attacker happens to be positioned on that exact request. Against that, we would be trading a change that takes minutes to reverse for one that takes months and depends on someone else’s release schedule. For a content site the arithmetic does not work. For a bank or a webmail provider it plainly does, which is why they are on the list and we are not.
Frequently asked
What is HSTS?
HSTS stands for HTTP Strict Transport Security. It is a response header that tells a browser to contact a site only over HTTPS for a stated number of seconds. Once the browser has cached that policy, it rewrites any http:// address for your domain to https:// itself, so no plaintext request is ever sent. RFC 6797 defines it.
What does the HSTS header do?
It hands the browser a policy to store and enforce. The max-age directive sets how long, includeSubDomains extends it to every subdomain, and preload signals that you want the domain compiled into browsers themselves. While the policy is live, plain HTTP requests get upgraded before they leave the machine, and certificate warnings cannot be clicked through.
Should I enable HSTS preload?
Only if you are confident your domain will serve HTTPS on every subdomain for years. Preloading closes the gap for browsers that have never visited your site before. The cost is reversibility, because removal rides browser release cycles and takes months. Most sites get almost all the protection from an ordinary one-year policy.
How do I remove HSTS?
Serve Strict-Transport-Security with max-age=0 over a working HTTPS connection. Browsers drop the policy on their next visit, though anyone who never returns keeps it until it expires on its own. You cannot disable HSTS over plain HTTP. If you preloaded the domain, use the removal form at hstspreload.org and expect to wait months.