Security headers
Copies this page as Markdown with context, so an AI can walk you through your case step by step.
Security headers tell the browser how to protect itself. Each one is a line of config and they stop common attacks.
What we check
| Finding | Severity | What the header is for |
|---|---|---|
| HTTP doesn’t redirect to HTTPS | Medium | Nobody should browse your site unencrypted |
| The redirect goes through another http:// address first | Low | It ends on HTTPS, but the first hop is unencrypted and doesn’t qualify for HSTS preload |
Missing Strict-Transport-Security (HSTS) |
Medium | Forces the browser to always use HTTPS |
| Short HSTS or no subdomains | Low | At least 6 months and includeSubDomains are recommended |
Missing Content-Security-Policy |
Medium (low if in report-only mode) | Limits where scripts can load from: stops XSS |
| Weak CSP | Low | A policy with unsafe-inline or * protects little |
CSP with unsafe-eval |
Info | It lets text run as code; some libraries need it |
Missing X-Frame-Options or frame-ancestors |
Medium | Stops your site being put in an iframe to trick clicks |
Missing X-Content-Type-Options |
Low | Stops the browser guessing a file’s type |
Missing Referrer-Policy |
Low | Controls what address is shared when leaving your site |
| Server version exposed | Low | Server: nginx/1.18.0 tells an attacker which flaws to try |
Cookies without Secure, HttpOnly or SameSite |
Low to high | They protect the session from theft and CSRF |
| Mixed content | Low, or medium if it’s a script | The HTTPS page loads files over HTTP |
| CORS allowing any origin with credentials | High | Another site could read your users’ data |
How to add them
nginx
Inside the site’s server block:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'none'" always;
server_tokens off;
Apache
In .htaccess or the VirtualHost (needs mod_headers):
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Vercel, Netlify and Cloudflare
On Vercel they go in vercel.json under headers; on Netlify, in the _headers file; on Cloudflare, in Rules → Transform Rules → Modify Response Header.
Content-Security-Policy, carefully
A badly built CSP can break your site. Start in report-only mode (Content-Security-Policy-Report-Only), watch the browser console to see what it would block, and only then switch to the real header.
Check
curl -sI https://your-domain.com | grep -iE "strict|content-security|x-frame|x-content|referrer|server"