Skip to the content
Start free

The HSTS header is set up wrongly

Strict-Transport-Security has no valid max-age, max-age=0, a very short time or two copies, so it protects less than it should.

Medium priority Security and HTTPS

Why it matters #

The standard for HSTS (RFC 6797) needs a max-age in seconds. Without a valid max-age, browsers ignore the header. max-age=0 tells them to forget the rule, and a very short time means the protection runs out between visits.

When the header is sent twice, browsers use only the first one, which may not be the one you meant. To join the browsers' HSTS preload list, the header also needs a max-age of at least one year, includeSubDomains and preload, and http must redirect to https.

How to fix it #

Send one header with one clear value, for example "Strict-Transport-Security: max-age=31536000", adding includeSubDomains once every subdomain works on https. Remove the second copy: often a plugin and the server or CDN both add one.

Ask for preload only when you are sure the whole domain will stay on https for good, because leaving the list is slow. Check with the Security Headers Checker.

What it looks like, and fixed #

The problem
strict-transport-security: max-age=0
strict-transport-security: max-age=31536000; includeSubDomains

Two copies, and browsers use only the first, which switches HSTS off.

Fixed
strict-transport-security: max-age=31536000; includeSubDomains

One header with one clear value. Leave out includeSubDomains if any subdomain is not on https.

Fix it with your AI assistant #

Paste this into ChatGPT, Claude, Gemini or your coding agent. Fill in the words in [square brackets] first. It checks before it changes anything, changes only this, and tells you how to prove it worked.

Your instruction for the AI
Help me correct the HSTS header on [your website address], which runs on [your platform or server, e.g. WordPress with a security plugin on nginx behind Cloudflare]. A checker says Strict-Transport-Security has no valid max-age, max-age=0, a very short time, or is sent twice. First check: run "curl -sI https://[your domain]/" (or ask me to paste the headers) and show me every Strict-Transport-Security line. Then find where each copy comes from: server configuration, .htaccess, a plugin, the CDN or the application code. Explain plainly what is wrong. Then give me the fix: one header, sent once, on https answers, with "max-age=31536000", plus includeSubDomains only if I confirm every subdomain works on https. Rules: back up first, remove only the extra or broken copies, keep all other headers, and do not add preload unless I ask. Give the exact lines to remove and to keep, with where they live. Finally, tell me to re-check with the URSY.com Security Headers Checker at ursy.com/security-headers-checker/.

We find the problems, and help you fix them

  1. Check Run a free tool or the full audit.
  2. Fix it with your AI Download your AI Fix Pack and drop it into ChatGPT, Claude or Gemini. A free account is enough.
  3. Re-check Come back, check again, and watch each fix turn green.

How the AI Fix Pack works, with a sample to download

Fix it on your platform #

WordPress

A security plugin and the server or host often both add the header. Turn it off in one of them so only one copy is sent.

Your server or hosting

Search the nginx or Apache configuration, and .htaccess files, for Strict-Transport-Security and keep a single line on the https site.

Your CDN (for example Cloudflare)

If the Cloudflare HSTS setting is on and the server also sends the header, switch one of them off and check the max-age value in the one you keep.

Check it is fixed #

Run the Security Headers Checker again: it should find exactly one Strict-Transport-Security header with a valid max-age of a year or more.

Official source #

RFC 6797: HTTP Strict Transport Security (HSTS)

Questions #

Why does sending it twice matter?

The HSTS standard tells browsers to use only the first header, so the copy you meant may be ignored.

How long should max-age be?

One year (31536000 seconds) is a common choice, and it is the minimum the preload list asks for. Very short times let the protection run out between visits.

More problems in Security and HTTPS

See every problem in the library

For AI assistants and developers: Instructions for AI · Developers · How to cite URSY.com