Home / Fix guides / Website security

HSTS max-age too short: how to fix it

Your site sends an HSTS header, but its max-age value is low, so browsers only remember to use HTTPS for a short time. Raise it to at least 31536000 seconds (one year) on your HTTPS responses, ideally in steps.

HSTS (HTTP Strict Transport Security) is a response header that tells browsers to only ever use HTTPS for your site. The max-age value says how many seconds the browser should remember that instruction. If the number is small, for example 300 or 86400, the protection runs out quickly and security scanners will flag it as too short.

What the problem looks like

Visitors see nothing. The problem only shows up in a scan report or when you look at your site's headers, for example:

Strict-Transport-Security: max-age=300

That is five minutes. Short values usually come from a test setting that was never raised, a hosting default, or a plugin or tool that set a cautious number. Scanners differ in the exact limit they use, but one year (31536000) is the widely recommended value.

Why it matters

With HSTS active, a browser that has visited your site will switch any http:// request to https:// by itself, before anything goes over the network. When the max-age is short, that memory expires fast. A returning visitor on public Wi-Fi can then make a plain HTTP request first, and someone on the same network could interfere before your redirect to HTTPS happens.

A long max-age is also a requirement for the browser HSTS preload list (it needs at least one year, plus includeSubDomains and preload). And it is a cheap fix that tends to appear in security reviews, so closing it early saves awkward questions later.

How to check your site

These are all free:

  • In your browser, open developer tools, go to the Network tab, reload the page, click the first request and read the Response Headers. Look for strict-transport-security.
  • From a terminal, run curl -sI https://example.com | grep -i strict-transport (use your own domain).
  • Run your domain through Qualys SSL Labs or securityheaders.com, which both report the HSTS value.

The header only counts when it is sent over HTTPS. Browsers ignore it on plain HTTP responses, so check the https:// address.

Before you raise the number

HSTS is hard to undo. Once a browser has seen a long max-age, it will refuse plain HTTP for your domain until that time runs out. So check these first:

  • Every page, image, script and font must load over HTTPS. If not, see mixed content warnings.
  • The site must already have working HTTPS and a redirect from HTTP. If not, start with no HTTPS on the site.
  • Only add includeSubDomains if every subdomain (including old ones like mail or staging) works over HTTPS. It is not needed to fix the "too short" finding.

If you are not fully sure, raise the value in steps and leave a few days between each: 300, then 86400 (one day), 604800 (one week), 2592000 (30 days), and finally 31536000 (one year). If your whole site is already clean HTTPS, going straight to one year is fine.

How to fix it

The target header is:

Strict-Transport-Security: max-age=31536000

Where you set it depends on your setup. Menu names vary by version, so treat these as pointers:

  • nginx: in the server block that listens on 443, add add_header Strict-Transport-Security "max-age=31536000" always; then test and reload nginx. Note that add_header lines in a location block can replace the ones set higher up.
  • Apache: with mod_headers enabled, add Header always set Strict-Transport-Security "max-age=31536000" to the HTTPS virtual host or .htaccess, then reload.
  • Cloudflare: usually under SSL/TLS, then Edge Certificates, then HSTS. Enable it and choose a max-age of 12 months.
  • IIS: newer versions have an HSTS option on the site in IIS Manager. Otherwise add the header as a custom header in web.config.
  • Netlify and Vercel: add the header in your _headers or netlify.toml file (Netlify), or vercel.json (Vercel).
  • WordPress: WordPress itself does not set this header. It is set by the web server, your host's control panel, or a CDN, so use the matching option above. See the WordPress guide for details. If you are on managed hosting, ask support to raise it.

Set the header in one place only. If your server and your CDN both add it, you can end up with two copies and unclear results.

If you have a developer or host, send them the target header above and the platform you use. It is usually a five minute change.

How to confirm the fix worked

  1. Run the same curl -sI https://example.com check again and confirm the value is 31536000 or higher.
  2. Check the site in a private browser window and click through a few key pages (home, contact, checkout or forms) to make sure nothing is blocked.
  3. Run SSL Labs or securityheaders.com again and confirm the HSTS line looks right.
  4. Re-run your security scan. Scanners cache nothing on your behalf, but a new result confirms the finding is gone.

If you want to join the preload list, check eligibility at hstspreload.org first. Preloading is very difficult to reverse, so only do it when you are certain every subdomain supports HTTPS.

How to stop it coming back

  • Keep the header in one documented place (server config, CDN or host setting) so it does not get lost.
  • Recheck after a host move, a new CDN, a server rebuild or a redesign. These often reset headers to defaults.
  • Keep your certificate renewing automatically. HSTS makes an expired certificate a hard error with no "continue anyway" button.
  • Scan regularly. SiteMonday's week 2 OpenVAS security scan flags this finding in a written report and ranked fix list, and you or your developer then make the change.

Step by step for your platform

Questions

What max-age should I use for HSTS?

Use 31536000 seconds (one year) once your whole site works on HTTPS. If you are unsure, step up gradually from 300 to a day, a week, a month and then a year.

Can I undo HSTS if something breaks?

Only partly. Browsers remember the old value until it expires, but if you serve max-age=0 over HTTPS, browsers that visit again will clear it. That is why stepping up slowly is safer.

Do I need includeSubDomains and preload?

No, not to fix a too short max-age. Add them only if every subdomain works over HTTPS, and preload only when you are certain, because removal from the preload list takes a long time.

Why does my HSTS header not show on http://?

Browsers ignore it on plain HTTP, and many servers do not send it there. Check the https:// address instead.

Will raising HSTS affect my search ranking?

It is a security setting, not a known ranking tool. Its value is protecting returning visitors from insecure connections.

I use Cloudflare or a host. Do I still need to change my server?

Usually you only need to set it in one place. If your CDN or host offers an HSTS setting, use that and avoid also adding the header on the server.

Related problems