Home » Security » Missing HSTS Header: What It Does and How to Add It Without Locking Yourself Out

Missing HSTS Header: What It Does and How to Add It Without Locking Yourself Out

Published 2026-10-03 | Security

Missing HSTS Header: What It Does and How to Add It Without Locking Yourself Out banner

HSTS (HTTP Strict Transport Security) is a response header that tells a browser: "for the next while, only contact this site over HTTPS, and refuse to use plain HTTP". Without it, a visitor who types example.com into the address bar is first sent to the HTTP version and relies on your redirect to reach HTTPS. That first request is the weak point.

What the header looks like

Strict-Transport-Security: max-age=31536000; includeSubDomains
  • max-age is how many seconds the browser should remember the rule. 31536000 is one year.
  • includeSubDomains applies the rule to every subdomain too.
  • preload is a request to be built into browsers' hard-coded lists (see the warning below).

Check whether you have it

curl -sI https://example.com | grep -i strict-transport

No output means the header is missing.

Before you turn it on

HSTS removes the option of reaching your site over HTTP. If anything about your HTTPS setup is shaky, HSTS turns that into a hard outage: browsers will not let visitors click through a certificate warning when HSTS applies.

Check first:

  • The certificate is valid and renewal is automatic (see expired certificates).
  • Plain HTTP redirects to HTTPS.
  • If you plan to use includeSubDomains, every subdomain works over HTTPS, including old ones like mail, dev or shop. One forgotten HTTP-only subdomain will stop loading for returning visitors.

Roll it out in stages

  1. Start small: max-age=300 (five minutes). Test the whole site.
  2. Raise it: one day (86400), then a week, then a month, checking that nothing breaks.
  3. Settle at a long value: max-age=31536000.
  4. Add includeSubDomains only after verifying all subdomains.

Each step teaches you something while mistakes are still cheap to undo.

How to add it

nginx (inside the HTTPS server block):

add_header Strict-Transport-Security "max-age=31536000" always;

Apache (needs mod_headers):

Header always set Strict-Transport-Security "max-age=31536000"

Cloudflare: SSL/TLS, Edge Certificates, "HTTP Strict Transport Security (HSTS)". Enable it and choose the max-age.

WordPress or shared hosting: many hosts have a toggle, or a security plugin offers it. If you edit .htaccess yourself, use the Apache line above.

Reload the server and re-run the curl check.

A warning about preload

The preload directive asks browser vendors to include your domain in a list shipped with the browsers, so even a first visit uses HTTPS. The requirements are strict (a long max-age, includeSubDomains and preload all present) and removal from the list is slow, taking months to reach all users. Do not add preload until you are certain every current and future subdomain will always have working HTTPS.

Common mistakes

  • Setting the header on HTTP responses, where it is ignored.
  • Leaving out always in nginx, so the header is missing on error responses.
  • Setting a one-year max-age on day one, then discovering a subdomain without HTTPS.
  • Adding it in two places (the app and the proxy) and sending a duplicate header.

HSTS is one of several response headers worth reviewing. It supports, but does not replace, a correct HTTPS setup: see HTTPS not working if the basics are not in place yet.

Frequently Asked Questions

Is a missing HSTS header a serious vulnerability?

It is a hardening gap, not a break in your site. Without it, the very first visit by a browser (or a visit after the policy expires) can be made over plain HTTP, which on an untrusted network can be intercepted and downgraded.

Can I set HSTS on an HTTP response?

No. Browsers ignore the header unless it arrives over a valid HTTPS connection.

Can I undo HSTS?

You can send max-age=0 to tell browsers to forget it, but only browsers that visit again will receive that. Visitors who do not return keep the old policy until it expires, which is why you should start with a short max-age.

Found a mistake or still stuck? Contact us. See how we write and check these guides in our editorial policy, or read about DocumentGuy.

More in Security