Understanding HTTP Strict Transport Security (HSTS)

Understanding HTTP Strict Transport Security (HSTS)

A user types a company’s domain into their browser without bothering to add https:// – muscle memory, decades of habit – and for a split second that request goes out in plain HTTP before anything redirects it. That split second is exactly the gap HTTP Strict Transport Security (HSTS) was built to close, and understanding how it works matters for anyone responsible for securing a website’s connections.

HSTS is a response header that tells a browser: never load this site over plain HTTP again, only HTTPS, for a specified amount of time. Once a browser has seen that header once, it will silently upgrade every subsequent request to that domain to HTTPS on its own, before a single byte travels over the network. No redirect, no round trip, no window for interception.

Why a redirect from HTTP to HTTPS isn’t enough

Many teams assume that redirecting http:// to https:// on the server covers them. It doesn’t, and this is the misconception worth busting first.

A server-side redirect still requires the browser to make an initial plain-HTTP request. That first request – and the 301 or 302 response that follows – travels unencrypted. On an open Wi-Fi network, a coffee shop router, or any point where an attacker sits between the user and the server, that first request is an opening for a man-in-the-middle attack. The attacker can intercept it and serve a fake page, strip out the redirect, or quietly proxy the whole session over HTTP while the browser’s address bar still looks normal enough for most users not to notice.

This is the classic SSL-stripping attack, and it’s precisely what HSTS was designed to prevent. With HSTS in place, the browser never sends that vulnerable first request at all – it rewrites http:// to https:// internally, before the request leaves the device.

How the header actually works

The header looks like this:

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

Three parts matter here:

max-age defines, in seconds, how long the browser should remember to enforce HTTPS-only for this domain. 31536000 seconds is one year, which is the commonly recommended baseline.

includeSubDomains extends the rule to every subdomain, not just the exact host that sent the header. This one deserves caution – more on that below.

preload is a signal requesting inclusion in the browser preload list, a hardcoded list shipped inside Chrome, Firefox, Safari and others that enforces HTTPS from the very first visit, even before the site has ever been reached.

That last point solves what’s called the trust-on-first-use problem. A standard HSTS header only protects a user after their first successful HTTPS visit to a domain. If their very first interaction with a site happens to be intercepted, the header itself never gets delivered. Preloading closes that gap by baking the rule into the browser itself, but getting a domain removed from the preload list later is slow and painful, so it’s not a setting to enable carelessly.

Rolling it out without breaking subdomains

The includeSubDomains directive is where teams get burned. It’s common for an organization to have a handful of subdomains still running on HTTP – an old marketing microsite, a staging environment, a partner integration that was never migrated. Enable includeSubDomains without checking first, and every one of those becomes unreachable in supporting browsers until it’s HTTPS-capable, with no way to quickly undo it since the browser has already cached the instruction for the full max-age.

A safer rollout looks like this:

1. Confirm every subdomain serves valid HTTPS before adding includeSubDomains.
2. Start with a short max-age, such as 300 seconds, and confirm nothing breaks.
3. Increase max-age gradually – a day, then a week, then a month – while monitoring for errors.
4. Once stable at a long duration, consider includeSubDomains.
5. Only submit to the preload list after the site has run cleanly at a long max-age for an extended period, since removal from preload can take months to propagate.

Skipping the gradual ramp-up is the single most common mistake seen in HSTS deployments – a header pushed straight to a one-year max-age with includeSubDomains, followed by a frantic rollback attempt that browsers simply ignore because the cached policy hasn’t expired yet.

What HSTS does not protect against

It’s worth being precise about scope. HSTS enforces transport-layer encryption, but it says nothing about certificate validity, cipher strength, or misconfigured TLS settings – those are separate concerns that require their own checks, and a site can have a technically correct HSTS header while still running weak or misconfigured TLS underneath. It also does nothing to stop XSS, SQL injection, or vulnerabilities in application logic. It’s one control among many that make up a defense-in-depth posture, not a silver bullet, and it doesn’t replace a properly configured Content Security Policy or other response headers doing their own job.

Checking whether it’s already working

Confirming HSTS is live doesn’t require special tooling – any browser’s developer tools will show the Strict-Transport-Security header in the network response for the initial page load. What’s harder to verify manually is whether the max-age is sensible, whether includeSubDomains is safe given the current subdomain inventory, and whether the setting is consistent across every environment a site runs in. This is the kind of configuration drift that periodic automated scanning is well suited to catching, alongside the rest of a site’s header posture, well before it turns into an incident.

Frequently asked questions

Does HSTS slow down page loads?
No. Once cached, the browser skips the HTTP request entirely and goes straight to HTTPS, which is actually faster than an HTTP-to-HTTPS redirect since it removes a network round trip.

Can HSTS be applied to a single page instead of a whole domain?
No. The header is scoped to the domain (and subdomains, if specified), not individual URLs. It’s an all-or-nothing setting per host.

What happens if the HTTPS certificate expires while HSTS is active?
The browser will refuse to load the site at all rather than falling back to HTTP, since HSTS explicitly forbids that fallback. This makes certificate renewal monitoring more important, not less, once HSTS is enabled.

Getting HSTS right is less about the header syntax and more about the rollout discipline around it – ramp up gradually, verify subdomains first, and treat preload submission as a one-way door rather than a quick toggle to flip on day one.