What is HSTS? The header that keeps browsers on HTTPS

By TechCompare · Updated · How we check

HSTS makes browsers skip plain HTTP for your site. Send Strict-Transport-Security with a long max-age on HTTPS responses, and add includeSubDomains and preload only when every subdomain serves HTTPS.

HTTP Strict Transport Security (HSTS) is a response header that tells a browser to reach a site only over HTTPS for a set time. After the first visit, the browser turns every http:// link into https:// on its own and won't let visitors click past certificate errors. It closes the gap a plain redirect leaves, where the first request still goes out unencrypted.

Topic
HSTS
Forcing HTTPS
Category
HTTPS setup
HSTS, ECH, redirects and compression

How this is calculated

The header looks like Strict-Transport-Security: max-age=31536000. The max-age is in seconds, one year in this case, and every new HTTPS response starts the clock again. RFC 6797 tells browsers to ignore the header when it arrives over plain HTTP, since an attacker could add or strip it there. So HSTS only kicks in after the first secure visit.

includeSubDomains extends the rule to every subdomain. That's what you want for security, but it breaks any subdomain still on plain HTTP, like an old intranet page or a router's admin panel, for everyone who has visited the main site.

preload asks for the domain to be built into browsers through the list at hstspreload.org, which Chrome, Firefox, Safari and Edge all draw on. Then even the very first visit is protected. To get on the list, a domain has to redirect HTTP to HTTPS on the same host, serve every subdomain over HTTPS, and send a max-age of at least one year with includeSubDomains and preload. Getting off the list can take months, because it ships with browser updates.

Roll it out in steps. Start with a max-age of five minutes, then a week, then a month, checking that nothing breaks each time, and finish at a year or more. That's the ramp hstspreload.org itself suggests.

The SSL Checker reads the Strict-Transport-Security header from the site's HTTPS answer and shows what it says.

Verdict

Send HSTS with a max-age of at least a year on every HTTPS response once your redirects work. Check every subdomain before adding includeSubDomains. Only add preload when you're sure the whole domain will stay on HTTPS for years, because leaving the list is slow.

More SSL scenarios

Frequently asked questions

Does HSTS replace the HTTP to HTTPS redirect?
No. Browsers that haven't seen the header yet, and tools that ignore it, still arrive over plain HTTP and need the redirect. HSTS only takes over after the first secure visit, unless the domain is preloaded.
How do I undo HSTS if something breaks?
Send max-age=0 over HTTPS. Browsers that see it forget the rule. Browsers that don't come back keep it until the old max-age runs out, which is why a short max-age is safer while you test.
Why does the checker show no HSTS on a site I know uses it?
The checker reads the home page's HTTPS answer without following redirects. If example.com redirects to www.example.com, the header may only be on the www answer, so check that name too. For the preload list, the redirect itself needs the header.