Strict-Transport-Security Header Not Set: How to Fix It

, by xura.tools team

TL;DR: Send this header on your HTTPS responses:

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

Only keep includeSubDomains if every subdomain works over HTTPS. If you're not sure, start with max-age=300 and raise it step by step. Leave preload out until you have read the preload section below. Check your site with our HSTS checker.

What is the Strict-Transport-Security header?

HSTS tells the browser: "for the next N seconds, only talk to this site over HTTPS." After the browser sees the header once, it changes any http:// link or typed address to https:// by itself, before a request leaves the machine. It also stops users from clicking through certificate errors on your site.

Scanners report it in different words. ZAP says "Strict-Transport-Security Header Not Set". Nessus says "HSTS Missing From HTTPS Server". They mean the same thing: your HTTPS response has no Strict-Transport-Security header.

The real risk

You probably already redirect HTTP to HTTPS. That's good, but the redirect itself travels over plain HTTP. Someone on the same network (open café Wi-Fi, a bad hotel router) can answer that first plain request and keep the user on HTTP. This is called SSL stripping.

HSTS closes that gap from the second visit on. The browser never sends the plain request again. It's not an emergency if you don't have it, because an attacker needs to be on the user's network. But its a cheap fix, and it matters most for sites with logins.

Two limits to know. HSTS only works after one successful HTTPS visit. And browsers ignore the header if you send it over plain HTTP, per MDN. Preload list solves the first visit, but has its own cost.

Before you turn it on

hstspreload.org suggests ramping up: 5 minutes (max-age=300), then one week (604800), then one month (2592000), then one year. Watch for broken pages at each step.

Some real values we saw with curl -sI on December 5, 2026:

github.com          strict-transport-security: max-age=31536000; includeSubdomains; preload
www.cloudflare.com  strict-transport-security: max-age=31536000; includeSubDomains
www.mozilla.org     strict-transport-security: max-age=31536000

How to add it on your server

nginx

Put it in the listen 443 server block only:

server {
    listen 443 ssl;
    server_name example.com;

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

always makes nginx send it on every status code, not only on 200 and redirects. And watch the inheritance rule: add_header directives are inherited from the parent block only if the current block has none of its own. If a location has any add_header, the HSTS line from server disappears there. Repeat it in that location, use an include snippet, or on nginx 1.29.3+ set add_header_inherit merge; (nginx docs).

Apache (.htaccess)

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

Needs mod_headers (a2enmod headers) and AllowOverride FileInfo. An .htaccess file applies to HTTP too. Browsers ignore HSTS over HTTP so that's harmless, but if you have access, the cleaner place is the <VirtualHost *:443> block.

Caddy

Caddy turns on HTTPS for you, but it doesn't send HSTS unless you add it:

example.com {
    header Strict-Transport-Security "max-age=31536000; includeSubDomains"
    reverse_proxy localhost:3000
}

IIS (web.config)

On IIS 10 version 1709 and newer, use the built-in <hsts> element. It lives in applicationHost.config under your <site>, and it only adds the header on HTTPS responses:

<site name="Contoso" id="1">
    <hsts enabled="true" max-age="31536000" includeSubDomains="true" redirectHttpToHttps="true" />
</site>

On older IIS, or if you can only edit web.config:

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

On ASP.NET Core, app.UseHsts() sends it. Its default max-age is 30 days (Microsoft docs). Set MaxAge in AddHsts(...) to change it.

Cloudflare (Transform Rules / _headers for Pages)

Cloudflare has a built-in setting. Go to SSL/TLS > Edge Certificates > HTTP Strict Transport Security (HSTS), select Enable HSTS, accept the warning, then pick max-age, subdomains and preload. Cloudflare's own warning: don't pause Cloudflare, switch DNS records to DNS only or turn off HTTPS while HSTS is on.

You can also use Rules > Overview > Create rule > Response Header Transform Rule with Set static. On Cloudflare Pages, add a _headers file to your build output:

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains

Next.js (next.config.js headers())

// next.config.js
module.exports = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [
          { key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' },
        ],
      },
    ];
  },
};

The Next.js docs example uses two years plus preload. Only copy that if you plan to preload.

Express (helmet)

import express from 'express';
import helmet from 'helmet';

const app = express();
app.use(helmet()); // sends max-age=31536000; includeSubDomains

To change it: helmet({ strictTransportSecurity: { maxAge: 300, includeSubDomains: false } }).

Spring Boot

Spring Security sends Strict-Transport-Security: max-age=31536000 ; includeSubDomains by default, but only on HTTPS requests. Behind a load balancer or proxy that ends TLS, your app sees plain HTTP and skips the header. That's the usual reason for this warning on Spring apps. Tell Spring to trust the proxy headers:

# application.properties
server.forward-headers-strategy=native

Or set it yourself:

http.headers(headers -> headers
    .httpStrictTransportSecurity(hsts -> hsts
        .includeSubDomains(true)
        .maxAgeInSeconds(31536000)));

WordPress (plugin-free option)

In your child theme's functions.php or a file in wp-content/mu-plugins/:

add_action( 'send_headers', function () {
    header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains' );
} );

This runs only for pages PHP renders. Static files your web server sends directly won't get it, so the server config is the better place if you can edit it.

How to check it worked

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

You should see one line. If you see two, it's set in two places (common with a proxy plus the app). Our live check shows it with the other headers, for example wikipedia.org. The HSTS tool also checks max-age and preload status, and you can test your own domain in the security headers tool.

Common mistakes

  1. Sending it only on www. includeSubDomains on www.example.com covers *.www.example.com, not api.example.com. Send it from the apex domain too.
  2. Starting at one year with includeSubDomains and finding out later that some forgotten subdomain is HTTP only.
  3. Adding preload without submitting, or submitting without thinking about the exit. The directive alone does nothing, the submission is the commitment.
  4. Missing always on nginx, so error pages go out without the header.
  5. Expecting it on http://. Scanners check the HTTPS response. Your HTTP side should just redirect. Our redirect checker tests that part.
  6. Letting the certificate expire. With HSTS, an expired certificate means users can't reach the site at all. If you're changing certificates for the Chrome P-256 change, our fix guide covers renewal on nginx, Caddy and Cloudflare.

FAQ

What is the strict transport security header?

It's a response header that tells the browser to use HTTPS only for your domain, for the number of seconds in max-age. It's defined in RFC 6797.

Strict-Transport-Security header not set on nginx, why?

Usually one of three reasons: it's in the port 80 server block instead of 443, a location block has its own add_header and drops it, or always is missing and you're testing an error page.

What does "HSTS missing from HTTPS server" mean?

It's Nessus's name for the same finding. Your HTTPS site doesn't send Strict-Transport-Security. The fix is the same.

What max-age should I use?

31536000 (one year) is the common value and the preload minimum. Start lower while you test.

Is HSTS enough on its own?

No. It forces HTTPS but doesn't control what your pages load. Look at a Content-Security-Policy and X-Content-Type-Options next.


Is your site affected? Run the free P-256 check.