HSTS
An HTTP redirect leaves the first request unencrypted.
Send HSTS over HTTPS so returning browsers go straight to the secure address.
Added Updated
What to do
When someone follows an HTTP link, the browser sends a request before your server can redirect it. After the browser receives a Strict-Transport-Security (HSTS) header over HTTPS, it upgrades future requests itself.
This example covers the domain and all its subdomains. Use includeSubDomains only when every subdomain can serve HTTPS.
Strict-Transport-Security: max-age=63072000; includeSubDomains
It tells browsers to use HTTPS for your site for the next two years, even if a link or a typed address says http://.
Redirect http://example.com to https://example.com on the same hostname first, and only then anywhere else. If the first hop goes straight to a different host, the browser never sees the header for the name the visitor typed.
How to check
curl -sI https://example.com | grep -i strict-transport-security
Or with weeb (get weeb):
weeb probe example.com --fix
Look at the HTTPS redirect and Strict-Transport-Security lines.
How to fix it
Start with a short max-age, such as 300 seconds, check nothing breaks, then raise it.
includeSubDomains covers every name under your domain. Be sure all of them serve HTTPS before you add it.
Preloading
Adding preload and submitting your domain to hstspreload.org bakes the rule into browsers, which closes the gap on the very first visit. Getting off the list again is slow, so do it only when every subdomain is on HTTPS for good.
Sources
- RFC 6797: HTTP Strict Transport Security fetched
- HSTS preload list: submission requirements and removal fetched
- weeb: terminal HTTP client with a site probe fetched
Changelog
- Explained the first visit and the subdomain setting.
- First version.