opyebAPI Bench

HSTS and preload: a checklist before you commit

Security · 6 min read

Strict-Transport-Security tells a browser to refuse plain HTTP to your domain for a period of time. It closes the window in which a first request can be intercepted and redirected, which TLS alone does not cover. It is also one of the few headers that is genuinely hard to undo.

What the header does

The directive takes a max-age in seconds, optionally includeSubDomains, and optionally preload. After the first HTTPS response carrying it, the browser rewrites http:// to https:// for that domain before sending anything. With includeSubDomains the rule covers every subdomain, and with preload the domain is embedded in browser builds so the protection applies even on the very first visit.

StageHeaderRisk
Testmax-age=300Low — expires in five minutes
Rampmax-age=86400; includeSubDomainsMedium — subdomains must be HTTPS
Commitmax-age=31536000; includeSubDomainsHigh — one year of enforcement
Preload...; preloadVery high — removal takes months

The subdomain trap

includeSubDomains is where most incidents happen. A forgotten staging host, an internal service on plain HTTP, or a legacy subdomain without a certificate becomes unreachable the moment the one-year header is cached. Enumerate every subdomain first, including the ones you think are unused, and make sure each one either serves HTTPS or is removed from DNS.

Preload requirements: a valid certificate, redirect from HTTP to HTTPS on the same host, max-age of at least 31536000, includeSubDomains, and the preload directive. The submission form is run by the Chromium project and removal is not immediate.

Rolling it out without a rollback

Start with a short max-age and no includeSubDomains. Watch for mixed-content errors and redirect loops for a week. Then add includeSubDomains with a short max-age, and only after that raise the max-age to a year. Preload should be the last step, after the domain has run a full year of enforcement without exception, because at that point you are asking browser vendors to encode the decision.

Interaction with other headers

HSTS does not replace a redirect or a certificate; it complements them. Once the header is cached, the redirect is never reached, so the redirect rule can stay for first-time visitors but is no longer the security boundary. Also check that your HSTS header is served on every response, including errors and API endpoints, because a cache miss on a 500 response is still an opportunity to downgrade.

Finally, document the exact values and the date they were set. When someone asks in two years why a subdomain cannot serve plain HTTP, the answer should be in a file, not in someone's memory.

What to monitor after enabling

Once the header is live, watch for three symptoms. Redirect loops appear when an HTTPS endpoint redirects back to HTTP while the browser rewrites it to HTTPS again. Mixed-content warnings appear when a page loads a subresource over HTTP and the browser blocks it. And sudden connection failures on a subdomain usually mean includeSubDomains reached a host without a certificate.

Rollback is slow by design, so the monitoring window should be long. Keep the short max-age for at least a week before raising it, and keep a list of every hostname covered, with the date each was confirmed to serve HTTPS. When the header is finally set to a year, the list becomes the document that answers future questions about why a host cannot serve plain HTTP.

  • Alert on TLS handshake failures per hostname.
  • Test every subdomain with a plain HTTP request after the change.
  • Record the date and value of each stage in the runbook.

Preload is not a badge

Being on the preload list signals that a domain has run HTTPS-only for a long time, not that it is more secure than a domain enforcing HSTS with the same max-age. If your domain has any hostname you cannot guarantee, skip preload and keep the one-year header. The protection for repeat visitors is nearly identical, and the cost of a mistake is measured in months.

Open the calculators and put these numbers to work on your own API.

Open API Bench

Frequently asked questions

Can I remove HSTS quickly if something breaks?

Only after the max-age expires. A browser that has cached a one-year policy will refuse HTTP to that domain for a year, and preload domains stay on the list in existing browser builds until they are updated.

Does HSTS apply to API subdomains?

With includeSubDomains, yes, and that is usually desirable. Without it, each subdomain needs its own header, which is easy to forget and leaves gaps.

Do I still need an HTTP to HTTPS redirect?

Yes, for first-time visitors and for clients that do not implement HSTS. The redirect is the fallback; HSTS is the guarantee for repeat visitors.

Sources

Related guides