HSTS Explained: How Strict Transport Security Protects Your Site

So what is HSTS? It is a response header (HTTP Strict Transport Security) that tells a browser to only ever talk to your site over HTTPS, never plain HTTP, even if someone types http:// or follows an old link. Once a browser has seen it, it refuses to load that site insecurely until the header's timer runs out.

Explainer6 min read

That small instruction closes a real gap. Redirecting http:// to https:// helps, but the very first insecure request still leaves the device before the redirect happens, and that moment is exactly where a downgrade attack lives. HSTS removes the gap by making the browser upgrade to HTTPS itself, before any request is sent.

Below: the downgrade attack HSTS prevents, what the max-age value actually does, and the trade-off involved in joining the browser preload list.

The downgrade attack HSTS is designed to stop

Even when a site redirects all HTTP traffic to HTTPS, the browser's first contact is often plain HTTP. Someone sitting between the visitor and the site (shared Wi-Fi, a tampered router, a hostile network) can intercept that first insecure request and quietly keep the connection on HTTP, serving a modified version of your page. The visitor never reaches the secure redirect. This is the classic SSL stripping, or downgrade, attack.

HSTS defeats it by moving the decision into the browser. Once a browser has received a valid HSTS header from your domain, it rewrites every future http:// request for that domain to https:// internally, before anything is sent. There is no insecure first request left to intercept, so there is nothing to strip.

What the max-age value actually does

A typical header reads: Strict-Transport-Security: max-age=31536000; includeSubDomains. The max-age is a number of seconds telling the browser how long to remember the HTTPS-only rule. 31536000 seconds is one year, a common and sensible choice. Each time the browser visits and sees the header again, the clock resets, so an active site stays protected continuously.

  • max-age: how long, in seconds, the browser enforces HTTPS-only for your domain. A real, non-zero value is what makes the header count.
  • includeSubDomains: extends the rule to every subdomain. Only add it once every subdomain works on HTTPS, or you can lock yourself out of one.
  • preload: a signal that you want to be added to the browsers' built-in list (see below). It does nothing on its own.
  • max-age=0: switches HSTS off and tells browsers to forget the rule, used when you genuinely need to roll it back.

The preload list and its trade-off

HSTS has one residual gap: the very first time a browser ever visits your domain, before it has seen the header, it has no rule to follow. The preload list closes that gap. It is a list, built into Chrome, Firefox, Safari and others, of domains treated as HTTPS-only from the start, with no first visit needed.

The trade-off is commitment. Getting on the list usually means a long max-age, includeSubDomains and a preload directive, then submitting your domain. Removal is processed in browser release cycles, so undoing it can take weeks or months. If any part of your site, or any subdomain, ever needs to run over plain HTTP, preload will break it and you cannot quickly reverse that. It suits sites confident that everything they serve, now and later, will always be HTTPS.

Free, instant, no account

See your site's security grade in seconds.

Free, instant, and no account needed to see your grade.

Scan my site free

Plain-English A to E grade in about 10 seconds. No account needed to see it.

How to add HSTS safely

The cautious path is to roll it out in stages rather than jumping straight to a year-long, preloaded header. A misconfigured subdomain or a forgotten HTTP service then surfaces while the rule is still short-lived and easy to undo.

  • Confirm HTTPS works everywhere first, including every subdomain and any old service, before going near includeSubDomains.
  • Start with a short max-age, for example a few minutes or hours, and watch for breakage.
  • Raise it to a longer period such as one year once you are confident nothing is left on HTTP.
  • Only consider includeSubDomains and preload when the HTTPS-only commitment is genuinely permanent.
  • Add the header in your web server or hosting config (Apache, Nginx, or your host's control panel); on many WordPress hosts this is a one-line server rule rather than a plugin.

How EB Security checks your HSTS

Our free scanner reads the response headers your site already serves and reports whether HSTS is present with a real, non-zero max-age, rather than sent as an empty or zero value. It does this passively, from the outside, alongside related encryption checks such as whether http:// redirects to https://, whether the TLS certificate matches your domain and comes from a trusted authority, and whether outdated TLS 1.0 or 1.1 is still accepted.

HSTS is a hardening header, so a missing one nudges your grade rather than sinking it; a critical problem like no working HTTPS or an untrusted certificate is what caps a grade. The check tells you whether the header is there and configured sensibly. It is a read-only external scan: it cannot enter you onto the preload list or change your server, so treat the result as a fast, clear signal of what to fix, then apply the header yourself in your hosting config.

HSTS tells browsers to load your site over HTTPS only, closing the first-request gap that downgrade attacks exploit. Use a real max-age, add includeSubDomains and preload only once you are certain every part of your site will always be HTTPS, and roll it out in stages so a mistake stays easy to undo.

Common questions

What is HSTS in simple terms?
HSTS is a small response header (HTTP Strict Transport Security) that tells a browser to only ever load your site over HTTPS, never plain HTTP. Once a browser has seen it, it upgrades any http:// link to https:// by itself before sending the request, so a downgrade attack has no insecure first request to intercept.
Is HSTS the same as having HTTPS or an SSL certificate?
No. HTTPS and a valid certificate encrypt the connection once it is secure. HSTS is a separate header that forces the browser to use HTTPS in the first place, so an attacker cannot keep a visitor on plain HTTP. You need working HTTPS before HSTS is any use, but HSTS adds protection that HTTPS alone does not.
What is a good max-age value for HSTS?
One year (max-age=31536000) is a common, sensible choice for a settled site. If you are adding HSTS for the first time, start much shorter, such as minutes or hours, confirm nothing breaks, then raise it. A zero value effectively turns HSTS off and tells browsers to forget the rule.
Should I use includeSubDomains and preload?
Only once you are certain every subdomain and service runs on HTTPS and always will. includeSubDomains applies the HTTPS-only rule to all subdomains, and preload bakes your domain into browsers so it is enforced from the very first visit. Both are slow to reverse, so they suit sites fully committed to HTTPS everywhere.
Will adding HSTS break my website?
It can, if part of your site or a subdomain still needs plain HTTP, because browsers will then refuse to load that part. This is why you confirm HTTPS works everywhere first and start with a short max-age. Done in stages, the risk is small and any issue is easy to undo while the timer is short.
How do I check whether my site has HSTS?
Our free scanner reads your site's response headers from the outside and tells you whether HSTS is present with a real, non-zero max-age, in about ten seconds, with a plain-English explanation and fix. It is a passive external check, so it reports what your site already serves rather than changing anything for you.

How safe is your website?

A free A to E grade in about 10 seconds. No account needed.

Check my site