Strict-Transport-Security
- What it does
- HSTS tells the browser to go straight to HTTPS for your domain for a set period. Someone types http://, clicks an old link or follows a bookmark from 2015, and the browser upgrades it before a single byte goes out in the clear.
- Risk if missing
- Without it, that first request can go out over plain HTTP. On hotel or coffee shop Wi-Fi, an attacker can intercept it and keep the victim on HTTP while they talk HTTPS to you (SSL stripping).
Recommended value: max-age=63072000; includeSubDomains; preload
<?php
// Child theme functions.php (or a small mu-plugin)
add_action('send_headers', function () {
header('Strict-Transport-Security: max-age=63072000; includeSubDomains; preload');
});Gotchas
- Don't add preload on day one. Getting off the browser preload list takes months, and you can't speed it up.
- includeSubDomains will break any subdomain still serving plain HTTP. That forgotten legacy.example.com box counts. Audit first.
- Roll out with a short max-age like 300, check nothing breaks, then raise it to one or two years.
- Browsers ignore HSTS on plain HTTP responses. It has to come back on the HTTPS response.