A security headers check reads the HTTP headers a website sends and looks for the ones that protect visitors: Strict-Transport-Security, Content-Security-Policy, X-Frame-Options (or frame-ancestors), X-Content-Type-Options, Referrer-Policy and Permissions-Policy. Missing headers leave the site more exposed to attacks such as cross-site scripting and clickjacking.
What each security header does
Strict-Transport-SecurityForces HTTPSStops: Downgrade & cookie theftContent-Security-PolicyAllow-lists scripts & sourcesStops: Cross-site scripting (XSS)X-Frame-Options / frame-ancestorsBlocks framingStops: ClickjackingX-Content-Type-OptionsNo MIME sniffingStops: Disguised script filesReferrer-PolicyTrims the referrerStops: Leaking private URLsPermissions-PolicySwitches off browser featuresStops: Abuse of camera, mic, locationRecommended security headers
A sensible starting point for most websites. Adjust the Content-Security-Policy to the scripts, fonts and images your site actually loads.
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
Content-Security-Policy: default-src 'self'; img-src 'self' https: data:; frame-ancestors 'none'
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Cross-Origin-Opener-Policy: same-originHow to add security headers
Nginx
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;Apache or LiteSpeed (.htaccess)
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set X-Frame-Options "SAMEORIGIN"
</IfModule>Cloudflare
Go to Rules → Transform Rules → Modify Response Header, create a rule for all requests and add each header. Turn on HSTS separately under SSL/TLS → Edge Certificates.
Next.js
// next.config.js
module.exports = {
async headers() {
return [{
source: "/(.*)",
headers: [
{ key: "Strict-Transport-Security", value: "max-age=63072000; includeSubDomains" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "X-Frame-Options", value: "SAMEORIGIN" },
],
}];
},
};How to read your grade
| Grade | What it usually means |
|---|---|
| A+ / A | HSTS, a working CSP and the basic headers are all set. |
| B | The basics are in place, but CSP is missing or weak. |
| C / D | Several important headers are missing; often a default hosting setup. |
| F | Almost nothing is set. Start with HSTS, X-Content-Type-Options and X-Frame-Options; they rarely break anything. |
Things to watch out for
- HSTS is hard to undo. Browsers remember it for the whole max-age. Make sure every subdomain works on HTTPS before you add includeSubDomains or submit to the preload list.
- Test CSP first. Use the report-only header until nothing legitimate is blocked.
- Remove version numbers. “Apache/2.4.41” or “PHP/7.4” in headers tells attackers exactly which known bugs to try.
- Headers don't fix outdated software. Keep WordPress, plugins and the server itself updated.
Check the certificate too with the SSL Checker. If you'd rather hand this over, my website security service covers headers, Cloudflare, HTTPS and malware clean-up.