Strict-Transport-Security: the HSTS response header
Strict-Transport-Security tells a browser to reach this host over HTTPS only for the number of seconds in max-age, and to refuse to let anyone click through a certificate warning for it.
At a glance
- Direction
- Response only. Browsers ignore it if a client sends it in a request.
- Defined in
- RFC 6797
- When absent
- No HTTPS memory. A typed or linked http:// URL makes one plaintext request before your redirect can answer it.
- Typical value
- max-age=31536000; includeSubDomains
- Ignored when
- The response arrived over plain HTTP, or the certificate was not trusted.
- In the headers checker
- Graded. It warns when max-age is missing, zero or short, and when includeSubDomains is absent.
In detail
The header only takes effect on a response that already arrived over a valid HTTPS connection. The browser then records the host for max-age seconds and rewrites every http:// URL for that host to https:// before a single byte leaves the machine. That is the real gain over a plain redirect: the plaintext request that a redirect still has to receive never happens at all.
max-age is a sliding window refreshed by every response carrying the header, so a site that sends it on every page keeps a memory that never quite expires. Setting max-age=0 is the documented way to withdraw the policy, and you have to keep serving that zero long enough for existing visitors to come back and see it. Simply deleting the header leaves old browsers pinned until their own timer runs out.
includeSubDomains applies the same rule to every name under the host, including the ones nobody remembers. If an internal hostname on the same domain still serves plain HTTP or a self-signed certificate, adding this token makes it unreachable rather than merely insecure, and the interstitial has no click-through option. Take an inventory of subdomains, including staging and mail hostnames, before you add it.
preload is not part of RFC 6797. It is a consent token for a hardcoded list compiled into browsers, which applies before the very first request to your domain is ever made. Getting listed requires a max-age of at least one year plus includeSubDomains, and removal takes months to reach real users, so treat inclusion as close to irreversible.
Examples
Strict-Transport-Security: max-age=31536000; includeSubDomainsStrict-Transport-Security: max-age=0Serve this over HTTPS for at least as long as your previous max-age, otherwise clients that do not return in that window stay pinned.
curl -sI https://example.com | grep -i strict-transport-securityThings that catch people out
- The header is ignored over plain HTTP, so adding it only to the http:// side of your config does nothing whatsoever.
- It is also ignored when the certificate is invalid, which means HSTS cannot rescue a site whose certificate has already expired.
- max-age counts seconds, not days. max-age=365 is a policy that lasts a little over six minutes.
- A forgotten subdomain on a self-signed certificate becomes hard-blocked the moment the parent domain sends includeSubDomains.
Try it: HTTP Headers Checker
Check a live URL or paste headers you already have. It grades six security headers from A+ to F and lists every other header the response returned.
HTTP Headers Checker
LOCAL · Browser-OnlyView HTTP response headers for any URL
Enter any website URL to fetch and analyze its HTTP response headers. We'll automatically add https:// if needed.
Why Check Security Headers?
Security headers protect your website against common attacks like XSS, clickjacking, and MIME sniffing. They're set by your web server and cost nothing to implement. Missing security headers are one of the most common findings in security audits.
Related HTTP headers
All http headers →Content-Security-Policy: directives, sources and reporting
How CSP directives are matched, what default-src actually falls back to, why unsafe-inline defeats the point of a policy, and how nonces and hashes work.
X-Content-Type-Options: nosniff and MIME sniffing
What nosniff stops a browser doing, why it is the safest security header to add, and the two kinds of resource it starts rejecting once you turn it on.
Location: where the client should go next
How Location works on each 3xx status, why it also appears on a 201 Created, whether relative URLs are allowed, and how to avoid an open redirect.
X-Frame-Options: DENY, SAMEORIGIN and clickjacking
What DENY and SAMEORIGIN do, why ALLOW-FROM never worked, and how CSP frame-ancestors supersedes this header while it is still worth sending.
Content-Security-Policy-Report-Only: testing a policy safely
How the report-only CSP header measures a policy without blocking anything, where the violation reports go, and when to run it alongside an enforcing policy.
Referrer-Policy: controlling what the Referer header leaks
Every Referrer-Policy value compared, what modern browsers do when the header is missing, and why URLs with tokens in them leak to third parties without it.
Tools for this
- HTTP Headers Checker Free online HTTP headers checker - view HTTP response headers for any URL
- SSL Certificate Checker Free online SSL certificate checker - check SSL certificate details and expiration
- Redirect Chain Checker Free online redirect chain checker - trace HTTP redirect chains and hops