Header guide · Strict-Transport-Security

Strict-Transport-Security (HSTS): what it is and how to enable it safely

Strict-Transport-Security tells browsers to use only HTTPS for your domain. Learn max-age, includeSubDomains and preload, and how to roll HSTS out safely.

The browser knows example.com as an HSTS host, so a link to http://example.com is upgraded to https:// before it is sent; no plain HTTP request reaches port 80.BROWSERHSTSNETWORKhttp://example.comKNOWN HOSTSexample.commax-age 1y · subsexample.com:443https://example.com:80
Known HSTS host: http:// becomes https:// before any request leaves the browser.
In short5 points
  • Strict-Transport-Security (HSTS) is an HTTP response header that tells the browser to reach your domain only over HTTPS, for the number of seconds set in max-age.
  • Once a browser has seen it, http:// links are upgraded before any request is sent, and certificate errors become hard errors the user cannot click through.
  • Browsers ignore the header on plain HTTP. Send it on HTTPS responses only, and redirect port 80 to HTTPS with a 301.
  • WebSec0 gives the full 20 points for max-age of at least one year with includeSubDomains, and the same header unlocks a TLS A+. preload is optional and does not change either grade.
  • Raise max-age in steps (five minutes, a week, a month, a year) and check every subdomain works over HTTPS before adding includeSubDomains. Preloading is hard to undo.

What is Strict-Transport-Security?

Strict-Transport-Security (HSTS) is an HTTP response header that tells the browser to reach your domain only over HTTPS. After the browser has received it once, it rewrites every http:// URL for that host to https:// before sending the request, for as long as max-age says. It also turns certificate errors into hard failures: the user gets no button to continue anyway.

A typical header looks like this:

HTTP
Strict-Transport-Security: max-age=31536000; includeSubDomains

This tells the browser to remember the HTTPS-only rule for one year and to apply it to every subdomain as well. A third, optional directive, preload, requests inclusion in the list of HSTS domains that browsers ship built in.

HSTS is common but often incomplete. In Scott Helme’s June 2026 crawl, 252,846 of the 819,002 top sites that responded sent the header (about 31%). Only 49.8% of those used includeSubDomains, and 69.2% set a max-age of at least one year.

What HSTS protects against

A site that redirects HTTP to HTTPS is still exposed on the request before the redirect. Someone typing example.com, an old http:// bookmark or a link in an email starts in plain HTTP. An attacker on the same network (public Wi-Fi, a compromised router) can answer that request, keep the victim on HTTP and read or change everything. This is called SSL stripping.

Threat What HSTS does
SSL stripping on the first HTTP request The browser never sends it: http:// is upgraded locally.
http:// links, bookmarks and typed URLs Same internal upgrade, for pages, scripts, images and API calls.
Users clicking through a fake certificate Certificate errors on an HSTS host cannot be bypassed.
Cookies leaking over HTTP No request goes out over HTTP, so cookies are not sent in clear text. Still set Secure on them, as the guide to secure cookies explains.

HSTS does not protect the very first visit: the browser learns the policy from an HTTPS response, so it has to get there once. The preload list, covered below, closes that gap. HSTS also does nothing for content: it is the Content-Security-Policy guide that covers what the page itself may load.

The three directives

Directive Required What it does
max-age=<seconds> Yes How long the browser remembers the rule, counted from the last response that carried it. 0 deletes the rule.
includeSubDomains No Applies the rule to every subdomain, such as www, api and mail.
preload No Not part of the standard. Requests inclusion in the preload list at hstspreload.org.

Directive names are case-insensitive and their order does not matter. Each browser restarts the max-age countdown on every response that carries the header, so a regular visitor stays protected as long as you keep sending it.

Common max-age values:

Value Duration Use
300 5 minutes First test in production
604800 1 week Second step
2592000 30 days Third step
31536000 1 year Minimum for a passing grade and for preload
63072000 2 years Common final value

Where to send the header

  • On HTTPS responses only. Browsers ignore Strict-Transport-Security received over plain HTTP, because an attacker could forge or strip it there.
  • On every HTTPS response, including redirects and error pages. A browser may land on a 404 or a redirect first, and the preload list requires the header on HTTPS redirects too.
  • On port 80, a 301 redirect to HTTPS, without the header. It would be ignored anyway.
  • Once per response. When a response carries several HSTS headers, browsers apply only the first one. Duplicates usually come from the application and the web server both adding it.
  • On every host you serve. includeSubDomains only reaches browsers that visited the parent domain. A visitor who goes straight to shop.example.com needs that host to send its own header.

A typical exchange looks like this:

HTTP
GET / HTTP/1.1
Host: example.com

HTTP/1.1 301 Moved Permanently
Location: https://example.com/
HTTP
GET / HTTP/2
Host: example.com

HTTP/2 200
strict-transport-security: max-age=31536000; includeSubDomains

Should you preload?

The preload list is a list of domains built into Chrome. Firefox, Safari and Edge base their own lists on it. A preloaded domain is HTTPS-only from the first visit, even on a brand-new browser.

To submit at hstspreload.org, the domain must:

  1. Serve a valid certificate.
  2. Redirect HTTP to HTTPS on the same host, if it listens on port 80.
  3. Serve every subdomain over HTTPS, including www and internal hosts.
  4. Send, on the HTTPS base domain, a header with max-age of at least 31536000, includeSubDomains and preload. Redirects on the HTTPS site must carry it too.

Preloading is a commitment. Removal goes through a form, and the change takes months to reach users with browser updates; other browsers give no timing. Until then, any subdomain that loses HTTPS is unreachable for those users.

The case for preloading is also weaker than it was. hstspreload.org now says HSTS is recommended but preloading is not, because Chrome and Safari upgrade HTTP navigations to HTTPS for every domain. Chrome’s “Always Use Secure Connections” setting becomes the default for public sites with Chrome 154, in October 2026. Those upgrades still let the user click through a warning when HTTPS fails, and they cover navigations; HSTS covers every request and gives no way through.

Our advice: deploy HSTS with includeSubDomains everywhere. Preload only a domain you fully control, with no plans to serve anything over HTTP on any subdomain. WebSec0 follows the same line: preload earns no points, and its absence costs none.

Roll it out without locking users out

A long max-age cannot be recalled: a browser that cached it keeps forcing HTTPS until it expires. Find out what breaks while the value is short.

  1. List your hosts. Check DNS for every subdomain, including old ones, internal tools and mail or VPN portals. Each one needs a valid certificate and a working HTTPS service before you use includeSubDomains.
  2. Redirect HTTP to HTTPS. A permanent 301 on port 80, to the same host, for every path.
  3. Start at five minutes. Send max-age=300; includeSubDomains, then browse your sites and subdomains and watch error rates.
  4. Raise it in steps. One week (604800), then one month (2592000). Wait a full max-age at each step before moving on.
  5. Settle on one or two years. max-age=31536000; includeSubDomains, or 63072000. This is the value WebSec0 grades as a pass.
  6. Add preload last, only if you decided to submit the domain, then submit it at hstspreload.org.
  7. Check the result. Look for the header on a page, a redirect and an error page with curl -sI https://example.com/, then scan the site with WebSec0.

If you need to back out, send max-age=0 over HTTPS. Browsers forget the rule the next time they fetch a response carrying it, so it only works while HTTPS keeps working.

Common mistakes

  • Sending the header over HTTP only. Browsers ignore it there. It must be on the HTTPS responses.
  • includeSubDomains with a subdomain still on HTTP. An intranet, a printer page or a legacy app stops loading for everyone who visited the parent domain.
  • Jumping straight to two years. A mistake then lasts two years in your visitors’ browsers.
  • Adding preload without meaning it. hstspreload.org treats a domain whose header carries preload as requesting inclusion, and it may be submitted through the form. Leave it out until you have decided.
  • Spaces around the equals sign. Write max-age=31536000. WebSec0 reads max-age = 31536000 as no valid max-age and grades it as a warning.
  • Missing the header on error pages. Nginx, for example, only adds the header to 4xx and 5xx responses when the directive ends with always.
  • Two HSTS headers. The application and the proxy both add one; browsers keep the first, which may be the weaker.
  • Relying on HSTS for HTTPS itself. HSTS does not fix a broken certificate chain or old TLS versions. It makes those errors fatal for your users.

How WebSec0 grades Strict-Transport-Security

HSTS is worth 20 of the 100 points in the WebSec0 headers grade, second only to CSP. The scanner fetches your page over HTTPS and reads the first Strict-Transport-Security header of the response:

What WebSec0 sees Status Points
No Strict-Transport-Security header Fail 0 / 20
max-age below 31536000, missing or unreadable Warning 10 / 20
max-age of at least one year, without includeSubDomains Warning 10 / 20
max-age of at least 31536000 with includeSubDomains Pass 20 / 20

HSTS also affects the TLS grade. A site whose TLS configuration would earn an A+ is held at A, with the reason “HSTS missing or weak”, unless its header passes the check above: max-age of at least one year and includeSubDomains. Other floors hold the grade lower: TLS 1.0 or 1.1, for example, caps it at C until you disable TLS 1.0 and 1.1 on Nginx or on the server that terminates TLS.

A few details follow from how the check works:

  • WebSec0 only scans over HTTPS, so the header on your port 80 redirect is never seen, as for browsers.
  • Same-host redirects are followed, up to three, and the final response is graded. A redirect between example.com and www.example.com is followed too. For any other off-host redirect, the headers of the redirect response itself are graded, so put HSTS on it.
  • preload changes neither grade. The scanner does not query the preload list either.

Step by step

Configure it on your server

Setting up every header at once? Read all security headers on Apache, all security headers on Caddy, all security headers on Nginx, all security headers on Traefik.

Questions

Frequently asked questions

What does the Strict-Transport-Security header do?

It tells the browser that your domain must only be reached over HTTPS. For the next max-age seconds, the browser rewrites every http:// URL for that host to https:// before sending it, and refuses to load the site if the certificate is invalid.

What is a good max-age value for HSTS?

One year (31536000) or two years (63072000) once the rollout is done. One year is the minimum for the HSTS preload list and for a passing grade in WebSec0. Start much lower, such as 300, while you test.

Should I send HSTS over HTTP?

No. Browsers ignore the header on plain HTTP responses, because an attacker on the network could add or strip it. Answer HTTP requests with a 301 redirect to HTTPS and send the header on the HTTPS response.

Does HSTS protect the first visit?

No. The browser only learns the policy from its first HTTPS response, so a first request over plain HTTP is still exposed. The HSTS preload list closes this gap by shipping your domain inside the browser.

Should I add my site to the HSTS preload list?

Only if every subdomain, now and in the future, can be served over HTTPS, and you accept that removal takes months. hstspreload.org itself now recommends HSTS but not preloading, because Chrome and Safari already upgrade HTTP navigations. WebSec0 does not need preload for any grade.

How do I disable HSTS?

Send Strict-Transport-Security: max-age=0 over HTTPS. Each browser drops the policy the next time it receives that response, so keep serving HTTPS until returning visitors have picked it up. It does not remove a domain from the preload list.

Do I still need HSTS now that browsers default to HTTPS?

Yes. Chrome's HTTPS-by-default mode shows a warning the user can bypass when HTTPS fails. HSTS turns the same failure into an error with no way through, and applies to every request to the host, not just the pages a user opens.

Does HSTS work on localhost or an IP address?

Not on IP addresses: the specification forbids browsers from recording an IP literal as an HSTS host. Test with a real host name, and do not enable includeSubDomains on a domain whose subdomains include development hosts served over HTTP.

References

Sources

  1. HTTPS by defaultGoogle Chrome Security Team

About the author

Portrait of Joshua Martinelle

Security engineer at Tenable

Security engineer at Tenable and web security researcher. He has disclosed more than 60 CVEs since 2020 and builds WebSec0.

Verify the change

Deployed it? Check it.

WebSec0 grades your TLS setup and security headers, including Strict-Transport-Security, in a few seconds. Free, no account.

Scan your site