HSTS: HTTP Strict Transport Security
HSTS is one response header that changes your security posture permanently: once a browser sees it for your domain, it refuses to connect over HTTP at all, eliminating downgrade attacks and the "type http:// manually" gap.
HSTS attributes
| Attribute | Meaning |
|---|---|
| max-age | Enforcement duration |
| includeSubDomains | All subdomains |
| preload | Preload list |
The header
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
- max-age: how long the browser remembers (seconds). Start small (300) while testing, raise to 31536000 once confident.
- includeSubDomains: forces HTTPS on every subdomain, including ones you add later.
- preload: permission to embed you in the browser-built-in list; the strongest form, and effectively irreversible.
What HSTS stops
- SSL-stripping attacks: the man-in-the-middle trick of downgrading to HTTP.
- Users typing http:// or clicking http links on the first visit after the policy is cached.
- Warnings suppressed: browsers fail hard instead of offering an override.
The deployment ritual
- Confirm HTTPS works on the apex, www, and every subdomain.
- Send max-age=300 for a week; watch for breakage.
- Raise to max-age=86400, then 31536000.
- Only then add includeSubDomains, and preload last, after submitting to hstspreload.org.
Rolling back preload is genuinely slow (list removal takes weeks through browser releases). Never preload a domain whose subdomains you do not fully control. Before locking subdomains behind includeSubDomains or preload, verify that your DNS CAA records authorize every origin and CDN issuer using the CAA record lookup.
Frequently asked questions
Does HSTS affect SEO?+
Google indexes HTTPS preferentially; HSTS signals and enforces commitment. Redirects remain necessary for HTTP requests.
Can I exclude one subdomain?+
Not with includeSubDomains active: that flag covers everything. Plan subdomains before enabling it.
What is HSTS for cookies?+
The same idea applies to cookies (Secure flag): HSTS complements it by forcing the transport itself.
I set max-age=0 to disable HSTS. Did it work?+
For browsers that saw the header: yes, max-age=0 expires the policy. Preload list removal is separate and slow.
Does my CDN handle HSTS?+
Cloudflare and others can inject it; check the response header to confirm what is actually being sent.
Related
Last verified: 2026-12-02