Skip to main content
HighHeadersOWASP A02:2021CWE-319

How to fix: Missing HTTP Strict Transport Security (HSTS)

The server does not send the Strict-Transport-Security header, which tells browsers to only connect via HTTPS.

Why it matters

Attackers could intercept traffic via man-in-the-middle attacks by downgrading the connection from HTTPS to HTTP.

HSTS instructs browsers to only access the site over HTTPS for a specified duration. Without it, users who type the URL without 'https://' or follow an HTTP link are vulnerable to SSL-stripping attacks.

How to fix it

  1. 1Add the Strict-Transport-Security header to all HTTPS responses.
  2. 2Set a max-age of at least 31536000 (1 year).
  3. 3Consider adding includeSubDomains and preload directives.
  4. 4Ensure your entire site works over HTTPS before enabling.

Code examples

Next.js (next.config.mjs)

JavaScript
const nextConfig = {
  async headers() {
    return [{
      source: '/(.*)',
      headers: [{ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' }],
    }];
  },
};
export default nextConfig;

Nginx

nginx
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;

Apache

APACHE
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"

Caddy

PLAINTEXT
header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"

Express (Node.js)

JavaScript
app.use((req, res, next) => {
  res.setHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
  next();
});

Deno (Hono)

TypeScript
app.use('*', async (c, next) => {
  await next();
  c.header('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
});

Bun (Elysia)

TypeScript
app.onAfterHandle(({ set }) => {
  set.headers['Strict-Transport-Security'] = 'max-age=63072000; includeSubDomains; preload';
});

References

Detected automatically by VulnRadar. The check id is hsts-missing, stable across every scan so you can filter or diff on it.

See every headers check

Questions

How severe is Missing HTTP Strict Transport Security (HSTS)?
VulnRadar rates this high severity in the headers category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id hsts-missing, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Missing HTTP Strict Transport Security (HSTS) map to?
It maps to CWE-319. In the OWASP Top 10 it falls under A02:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for missing http strict transport security (hsts)

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Missing HTTP Strict Transport Security (HSTS) | VulnRadar