Enable HTTP Strict Transport Security (HSTS)
Updated 1 Dec 2026
What it means
Your site does not tell browsers to always use HTTPS. A visitor who types your address or follows an old http:// link makes a first unencrypted request that an attacker on the same network (public Wi-Fi, a compromised router) can intercept and redirect.
Why it matters
Customers on untrusted networks can be silently downgraded to an insecure connection, exposing logins and session cookies. Many compliance checklists (PCI DSS, ISO 27001 audits) flag missing HSTS.
How to fix it
- Make sure every page and subdomain already works over HTTPS (HSTS breaks anything that is HTTP-only).
- Add the Strict-Transport-Security header on HTTPS responses, starting with a short max-age (e.g. 300) to test.
- Raise max-age to 31536000 (one year) once nothing breaks; add includeSubDomains when all subdomains support HTTPS.
- Optionally add preload and submit the domain at hstspreload.org once you are confident.
Careful: Do not add includeSubDomains or preload until every subdomain serves valid HTTPS; browsers will refuse to load HTTP-only subdomains.
Configuration examples
nginx (server block (443))
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Apache (.htaccess or VirtualHost *:443)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
IIS (web.config)
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
</customHeaders>
</httpProtocol>
</system.webServer>
Cloudflare
SSL/TLS -> Edge Certificates -> HTTP Strict Transport Security (HSTS) -> Enable, Max Age: 12 months, Include subdomains: On
Node.js / Express
import helmet from 'helmet';
app.use(helmet.hsts({ maxAge: 31536000, includeSubDomains: true }));
Django (settings.py)
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_SSL_REDIRECT = True
Laravel / PHP (app/Http/Middleware/SecurityHeaders.php)
$response->headers->set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
Any platform
Strict-Transport-Security: max-age=31536000; includeSubDomains
Check your fix
curl -sI https://YOUR_DOMAIN | grep -i strict-transport-securityRe-run the Security Headers scan.
References
- https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security
- https://owasp.org/www-project-secure-headers/