Skip to content
ScanAnt

What is HSTS (HTTP Strict Transport Security)?

HSTS (HTTP Strict Transport Security) is a response header that tells a browser to use only HTTPS for your domain for a set period. After the first visit the browser upgrades every http:// request itself, so an attacker on the network cannot downgrade the connection.

How it works

A redirect from http to https is not enough on its own, because the first plain-http request can be intercepted before the redirect arrives. With HSTS, the browser remembers for max-age seconds that your host must be loaded over HTTPS, and rewrites links before any request leaves the device. Adding includeSubDomains extends the rule to all subdomains, and preload lets you request inclusion in the list built into browsers, which also protects the very first visit.

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

# nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

How to tell if your site is affected

  • The HTTPS response does not contain a Strict-Transport-Security header.
  • max-age is very short (for example 300 seconds), so browsers forget it quickly.
  • The header appears on the HTTP response only. Browsers ignore HSTS sent over plain http.
  • Only the www host or only the apex domain sends the header, and the other one does not.

How to fix it

  1. Make sure every page works over HTTPS and the certificate renews automatically, since HSTS turns certificate problems into hard errors.

  2. Redirect http to https permanently, then send Strict-Transport-Security: max-age=31536000 on HTTPS responses.

  3. Start with a short max-age such as one day, check that nothing breaks, then raise it to a year.

  4. Add includeSubDomains only after confirming every subdomain has valid HTTPS. Request preload only if you are ready to keep it permanently.

  5. On Vercel, Netlify and Cloudflare, add the header in the platform config. For Next.js use the headers() function in next.config; for WordPress set it in the server or a headers plugin.

How ScanAnt checks for it

Quick scan

The free quick scan checks whether your HTTPS response sends the header, whether max-age is long enough and whether the http address redirects to https. It reads one normal page load and needs no signup. It does not check the browser preload list.

Questions

Does HSTS replace an http to https redirect?

No, keep both. The redirect handles first visits and clients that have never seen the header, and HSTS protects the later visits.

What max-age should I use?

One year (31536000 seconds) is the common target and the minimum for preload. Roll up to it gradually.

Can HSTS lock me out of my own site?

If you enable it and later let the certificate expire, browsers that saw the header will refuse to load the site until the certificate is fixed. Automatic renewal avoids this.

Does HSTS protect against all man-in-the-middle attacks?

It protects against downgrade to plain http and stripped HTTPS. It does not help with a first visit before the header was seen unless the domain is preloaded.

See if your site is affected

Free for any public site, no signup. Need the verified or deep scan? Choose the level on the scan page.

Choose a scan level →