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
- 1Add the Strict-Transport-Security header to all HTTPS responses.
- 2Set a max-age of at least 31536000 (1 year).
- 3Consider adding includeSubDomains and preload directives.
- 4Ensure your entire site works over HTTPS before enabling.
Code examples
Next.js (next.config.mjs)
const nextConfig = {
async headers() {
return [{
source: '/(.*)',
headers: [{ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' }],
}];
},
};
export default nextConfig;Nginx
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;Apache
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"Caddy
header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"Express (Node.js)
app.use((req, res, next) => {
res.setHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
next();
});Deno (Hono)
app.use('*', async (c, next) => {
await next();
c.header('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
});Bun (Elysia)
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.
More headers checks
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.