Redirecting http:// to https:// is a good start, but the redirect itself travels over plain HTTP. Anyone positioned on the same network as a visitor, such as a hostile Wi-Fi hotspot, can answer that first unencrypted request before your redirect ever arrives. The Strict-Transport-Security header, usually shortened to HSTS, closes most of that gap: once a browser has received it over HTTPS, it rewrites every later http:// request for your host to https:// on its own and refuses to let visitors click past certificate errors.
Two things go wrong in practice. Either the header is missing entirely, which is what the Sitelemetry finding http.header.hsts.missing reports, or it is present with a max-age so short that the protection expires between visits, which is what mitm.hsts.max-age.short reports. Both are easy to fix, but the fix has a one-way quality: a browser that stored a long policy keeps it until it expires, so a careless value can lock visitors out of a subdomain that cannot serve HTTPS.
This guide explains what HSTS does and does not do, how to choose max-age through a staged rollout, when includeSubDomains is safe, where to set the header (web server, CDN or application), and how to verify the result. All examples use example.com. Preloading is a separate decision, covered at the end of section 4 and in the HSTS preload guide on our blog.
Scope of this guide
This guide covers the Strict-Transport-Security header as seen from outside: public responses and redirects. Automated checks read only the responses they receive, cannot see internal subdomains or browsers' stored policies, and are not a penetration test.
1. What HSTS does, and what it does not
HSTS is defined in RFC 6797. A server sends a response header such as Strict-Transport-Security: max-age=31536000 over HTTPS. From then on the browser treats the host as a known HSTS host for the number of seconds in max-age, and it applies two rules:
- Automatic upgrade. Any
http://URL for that host, typed by a person, followed from a link or loaded as a sub-resource, is rewritten tohttps://before a request leaves the device. No plain HTTP request is sent, so there is nothing to intercept. - No click-through on certificate errors. If the TLS connection has any certificate problem, such as an expired certificate, a wrong hostname or an untrusted issuer, the browser must end the connection without offering the usual “proceed anyway” option. That prevents an attacker from presenting a forged certificate and hoping the visitor clicks through.
What HSTS does not do matters just as much:
- It does nothing on the very first visit, before the browser has seen the header. That bootstrap gap is what the preload list exists for.
- It is ignored when received over plain HTTP. RFC 6797 tells browsers to discard the header on insecure connections, so adding it to your port 80 responses has no effect.
- It does not apply to IP addresses, only to host names.
- It does not replace your HTTP-to-HTTPS redirect. Visitors who have never received the header, and clients that do not support HSTS, still depend on the redirect.
- It does not fix mixed content, weak TLS settings or insecure cookies. It is one layer among several, which is why the TLS and security headers guide treats them together.
2. Why a missing HSTS header matters
Picture a returning customer on hotel Wi-Fi who types example.com into the address bar. Without HSTS, many browsers still send a first request over HTTP and receive your redirect to HTTPS. On a hostile network, an attacker can intercept that first request and keep the visitor on a plain HTTP copy of the site, relaying traffic to the real HTTPS site in the background. This is usually called an SSL stripping or downgrade attack. Anything the visitor submits on the stripped page, and any session cookie not marked Secure, can be read or changed.
With HSTS stored, the browser never sends that HTTP request: it upgrades internally and connects over TLS directly. The attacker’s only remaining option is a forged certificate, and HSTS removes the visitor’s ability to accept one.
The risk is real but bounded, and it helps to describe it calmly to stakeholders:
- It requires an attacker on the network path, not just anyone on the internet.
- Modern browsers increasingly try HTTPS first for navigations typed without a scheme, which narrows the window. HSTS turns that best-effort behaviour into a firm rule for your host and also removes the option to click through certificate errors.
- The OWASP HSTS cheat sheet recommends the header for any site served over HTTPS, and it costs almost nothing to send once your HTTPS setup is stable.
This is why a missing header on an HTTPS site is reported as a medium-severity finding rather than a critical one: the protection is cheap, broadly recommended and absent, but exploiting its absence needs a specific position on the network.
3. The header’s directives and how browsers read them
The header has one required directive and one optional one that browsers act on:
max-age=<seconds>(required): how long the browser should remember the policy. The countdown restarts each time the browser receives the header again, so frequent visitors stay protected continuously.max-age=0tells the browser to forget the policy.includeSubDomains(optional): extends the policy to every subdomain of the host that sent it.preloadis not part of RFC 6797. Browsers ignore it; it only signals consent to the preload list maintainers.
Directive names are case-insensitive, and unknown directives are silently ignored. That second rule is why typos are dangerous: nothing warns you. The table below shows how common real-world values behave.
| Header observed on an HTTPS response | What the browser does | Assessment |
|---|---|---|
No Strict-Transport-Security header | Stores nothing; every visit can start over HTTP | Missing; add the header |
max-age=300 | Enforces HTTPS for five minutes after each visit | Fine as a first rollout stage, too short to keep |
max-age=2592000; includeSubDomains | Enforces HTTPS on the host and its subdomains for 30 days | Reasonable intermediate stage, still below 180 days |
max-age=31536000; includeSubDomains | Enforces HTTPS for one year after each visit | The common long-term value, matching the OWASP example |
max-age=0 | Deletes any stored policy for the host | Deliberate switch-off; only use when rolling back |
includeSubDomains with no max-age | Header is invalid and ignored | Broken; max-age is required |
max-age=31536000; includeSubdomain | Misspelled directive ignored; subdomains not covered | Silent misconfiguration |
Two Strict-Transport-Security headers | RFC 6797 says only the first is processed | Pick one layer to own the header |
RFC 6797 also allows the value to be written in quotes, as in max-age="31536000". It is valid, but the plain unquoted form is what every reference uses and what monitoring tools parse most reliably, so prefer it.
4. Choosing max-age: a staged rollout
A long max-age is the goal, because protection should outlast the gap between visits. The OWASP cheat sheet uses one year (31536000) in its examples, and the preload list requires at least one year. But a long value is also a commitment: if something on the host stops working over HTTPS, browsers that stored the policy will refuse plain HTTP until the policy expires. Start small and grow it.
| Stage | Header value | Keep it for at least | What to check before moving on |
|---|---|---|---|
| 0. Prepare | No header yet | Until HTTPS is solid | Valid certificate with automated renewal, HTTP-to-HTTPS redirect, no mixed content |
| 1. Five minutes | max-age=300 | A few days of normal traffic | Error logs, support tickets, pages still linking to http:// assets |
| 2. One week | max-age=604800 | 1 week | Sign-in, checkout, embedded widgets, admin pages |
| 3. One month | max-age=2592000 | 1 month | Monthly jobs, email links, rarely used paths |
| 4. Long term | max-age=31536000 (or 63072000, two years) | Ongoing | Certificate expiry monitoring, every new subdomain if includeSubDomains is on |
Why wait at each stage? Because rolling back only reaches browsers that come back and receive a new header, and a browser that stored max-age=604800 may enforce it for a week without visiting. Waiting at least the length of the current stage means you have seen the full consequences before you commit to more.
Where does “too short” begin? There is no single rule in the RFC. Sitelemetry flags values under 180 days (15,552,000 seconds) as a low-severity finding, because a policy that lapses within a few months leaves infrequent visitors unprotected again. During stages 1 to 3 that finding is expected; treat it as a reminder to finish the rollout rather than an emergency.
About preload. Adding preload and submitting your domain to hstspreload.org builds HTTPS-only access into browsers for the domain and every subdomain, even on first visits, and removal takes months. Leave the directive out unless you have made that decision on purpose; the HSTS preload guide walks through the requirements and risks.
5. includeSubDomains: when it is safe
includeSubDomains makes the policy apply to every name below the host that sent it. Sent from example.com, it covers www.example.com, shop.example.com, intranet.example.com and printer.office.example.com alike, whether or not those hosts are public. That is its strength, because it also protects cookies scoped to the parent domain, and its main risk.
Hosts that commonly break under it:
- Internal tools that resolve only on the company network and were never given a public certificate.
- Device admin pages for routers, printers or storage boxes with self-signed certificates.
- Old staging or campaign hosts that still answer only on port 80.
- Third-party services on a CNAME, such as a help desk, status page or email click-tracking domain, that serve HTTP only or a certificate for another name.
In a browser holding the policy, these fail with a hard error and no way past it. Before enabling the directive, build an inventory: export your DNS zones, list the names on your certificates, and search Certificate Transparency logs for your domain. Test each name with curl -sS -o /dev/null -w '%{http_code}\n' https://name.example.com/.
Two scope details often surprise people:
- A policy set by
www.example.comcoverswww.example.comand names below it, but never the parentexample.comor siblings likeshop.example.com. To protect the whole domain, the apex itself must send the header, including on its redirect to www. - A policy from the apex only reaches a browser that actually requests the apex over HTTPS. If visitors only ever open www, they never receive it, so send the header on www as well.
If you cannot vouch for every subdomain, ship HSTS without includeSubDomains first. Protecting the main host for a year is far better than protecting nothing while you finish the inventory.
6. Where to set the header: server, CDN or application
Choose one layer to own the header. When a CDN and the origin both add it, visitors receive two headers and, per RFC 6797, browsers use only the first, which may not be the one you just edited.
nginx
Add it in the HTTPS server block with always, so error responses carry it too. Without always, nginx adds headers only to a fixed set of success and redirect status codes. Also note that add_header directives are inherited from the enclosing level only if the current level defines none, so a location block with its own add_header drops the server-level HSTS line unless you repeat it (nginx headers module).
server {
listen 443 ssl;
server_name example.com www.example.com;
add_header Strict-Transport-Security "max-age=300" always;
}Apache
With mod_headers enabled, set it inside the port 443 virtual host. The always condition applies the header to error responses as well, and set replaces any existing value instead of adding a duplicate.
<VirtualHost *:443>
ServerName example.com
Header always set Strict-Transport-Security "max-age=300"
</VirtualHost>CDN or reverse proxy
Most CDNs offer HSTS as a setting. In Cloudflare it lives under SSL/TLS, Edge Certificates, with separate controls for max-age, subdomains and preload, and its documentation warns that the setting can make the site unreachable if HTTPS later breaks. If the CDN owns HSTS, remove it from the origin, or make sure the CDN replaces rather than appends.
Application frameworks
- Django: the
SecurityMiddlewaresends HSTS whenSECURE_HSTS_SECONDSis non-zero, withSECURE_HSTS_INCLUDE_SUBDOMAINSandSECURE_HSTS_PRELOADas switches. It only adds the header to requests it sees as secure, so behind a TLS-terminating proxy configureSECURE_PROXY_SSL_HEADERcorrectly, or the header never appears. - Express: middleware such as Helmet sends HSTS by default; review its default max-age and subdomain options against your rollout stage rather than accepting them blindly.
- Rails:
config.force_sslenables the redirect and HSTS together; its HSTS values can be tuned through the SSL options. - Next.js and similar: a
headers()rule in the framework config works, but only for responses the framework serves. Static files from another layer will not carry it.
Setting HSTS at the edge or web server usually gives the most consistent coverage, because it applies to every response, including static files and error pages the application never touches.
7. How to verify the header
Start from a terminal. Check the apex, the www host and the HTTP entry point:
curl -sS -D - -o /dev/null https://example.com/
curl -sS -D - -o /dev/null https://www.example.com/
curl -sS -D - -o /dev/null http://example.com/The first two should each show exactly one strict-transport-security line with the value you expect, even if the response is a redirect. The third should be a 301 or 308 to HTTPS; it needs no HSTS header because browsers ignore it there. On Windows, use curl.exe and -o NUL.
Then check the places headers commonly go missing:
- A 404 page:
curl -sS -D - -o /dev/null https://example.com/this-page-does-not-exist - A static asset and an API route, if they are served by different layers.
- The response with your CDN bypassed, if you can reach the origin directly, to spot duplicates between layers.
In the browser, open Chrome DevTools, Network panel, and load the page: the response headers show the policy. After the browser has stored it, type http://example.com/; the first entry appears as 307 Internal Redirect with Non-Authoritative-Reason: HSTS, showing that the upgrade happened locally. The page chrome://net-internals/#hsts lets you query a domain and see its stored dynamic policy, including the expiry, and delete it while testing.
Finally, re-check after any change to your CDN, load balancer, framework version or hosting plan. Header configuration tends to be lost during migrations, and a scheduled automated scan catches that faster than a manual check.
8. Lowering or removing HSTS safely
Sometimes you need to back out, for example when a subdomain turns out to need plain HTTP while includeSubDomains is on. The order matters:
- Keep HTTPS working with a valid certificate on the host that sends the policy. A browser can only receive the new value over HTTPS.
- Send the reduced policy: drop
includeSubDomains, lowermax-age, or sendmax-age=0to clear the policy entirely. - Fix the underlying problem in parallel. The quickest relief for a broken subdomain is usually giving it a valid certificate, not removing HSTS.
- Expect a tail. Visitors who do not return keep the old policy until it expires, which is exactly why the staged rollout in section 4 exists.
If the domain is on the preload list, the header change alone is not enough; removal goes through hstspreload.org and reaches browsers only with updates.
9. What Sitelemetry checks
Two passive security modules look at HSTS. Both run in every scan profile on every plan: Free ($0), Starter ($49/month), Professional ($149/month) and Enterprise ($249/month). They read only what any visitor receives, so they need no ownership verification on their own: the free Launch Readiness Snapshot runs them without signup, and a Free-plan security audit runs them even before you verify the site. A security audit that also includes checks that need ownership proof, as paid-plan audits do by default, asks you to verify the site first.
http.header.hsts.missing(HTTP security headers module, severity medium): when the address you scan is HTTPS (a bare domain counts as https://), the module requests the home page (root URL) of the scanned origin, follows redirects and reads the final response. If that response has noStrict-Transport-Securityheader, the finding is raised with the evidence “Strict-Transport-Security not present”. It checks for presence only, not the value. If the response is a bot challenge, an access denial or an edge error page, the module reports the result as not measured instead of flagging headers that belong to the protection layer.mitm.hsts.max-age.short(HTTPS posture module, severity low, confidence medium): the module requests the home page of the site’s HTTPS origin, follows redirects and reads the HSTS header of the final page. This check runs when you enter a bare domain or an https:// address; for an http:// address the module runs its HTTP-to-HTTPS redirect check instead. Ifmax-ageis greater than zero but below 15,552,000 seconds (180 days), the finding is raised with the observed header as evidence. A challenge page or an unusable status code makes the result inconclusive.
Limits to know: neither check evaluates includeSubDomains, preload, duplicate headers, your subdomains or preload list status. A value of max-age=0, or a value the check cannot read as a plain number, is not reported as short. Both checks follow redirects and judge only the final page, so a redirect without the header, such as the apex redirecting to www, is not flagged. Use the curl commands in section 7 for those. Sitelemetry is an automated audit tool, not a penetration test or a compliance attestation. To see the header results first, try the free security headers checker; the security headers check guide covers the other headers, and the website security audit guide gives the wider picture.
Common questions
What max-age should I use for HSTS?
For the long term, one year (31536000 seconds) is the common choice and matches the OWASP example; two years (63072000) is also used. Reach it in stages, for example 300 seconds, one week and one month, checking for breakage at each stage before you increase it.
Why does my site still show the HSTS header as missing after I added it?
Common causes are adding it only to the HTTP server block, where browsers ignore it; an nginx location block with its own add_header lines that drops the inherited one; a framework that only sends it on requests it sees as secure behind a proxy; or a CDN serving cached responses. Check the live HTTPS response with curl.
Is includeSubDomains required?
No. It is optional and only required for preload list submission. Use it once you have confirmed every subdomain, including internal and vendor-hosted ones, serves HTTPS with a valid certificate. Until then, HSTS on the main host alone still protects its visitors.
Should I send HSTS on the HTTP redirect?
It does no harm but has no effect: RFC 6797 tells browsers to ignore the header when it arrives over plain HTTP. What matters is that every HTTPS response carries it, including an HTTPS redirect from the apex to www.
How do I turn HSTS off if something breaks?
Keep HTTPS working and send max-age=0 over HTTPS, or a lower value without includeSubDomains. Browsers update only when they receive the new header, so visitors who do not return keep the old policy until it expires. Fixing the certificate on the affected host is usually faster.
Sources & further reading
- RFC 6797: HTTP Strict Transport Security (HSTS)www.rfc-editor.org
- MDN: Strict-Transport-Security headerdeveloper.mozilla.org
- OWASP HTTP Strict Transport Security Cheat Sheetcheatsheetseries.owasp.org
- HSTS Preload List Submissionhstspreload.org
- nginx: ngx_http_headers_module (add_header)nginx.org
- Apache HTTP Server: mod_headershttpd.apache.org
- Cloudflare: HTTP Strict Transport Security (HSTS)developers.cloudflare.com
Prepared by the Sitelemetry editorial team. Explore the linked sources for further detail.



