Schema and trust
Security headers: five headers that protect your visitors
Security headers protect visitors from clickjacking, sniffing and downgrade attacks. Each of five headers earns a point. Copy-paste configs inside.
- Category
- Schema and trust
- Points available
- 5 pts
- Effort
- Medium effort
Why it matters
These headers tell the browser to use HTTPS only, refuse to be framed by other sites, not guess file types, and limit what is leaked in the referrer. They close common attack paths at almost no cost.
They also signal a well-maintained site, which matters for trust and for security scanners your customers may run.
How we measure it
We read the response headers of the final URL. One point each for: Strict-Transport-Security; Content-Security-Policy; X-Frame-Options or a CSP with frame-ancestors; X-Content-Type-Options: nosniff; Referrer-Policy.
Content-Security-Policy-Report-Only does not count, because it enforces nothing.
| Result | Points |
|---|---|
| All five present | 5 |
| Each header present | 1 |
| None | 0 |
How to fix it
- Add the headers at the web server, CDN or framework level so they apply to every page.
- Start CSP safely with
frame-ancestors 'self'; upgrade-insecure-requests. Build a stricter policy later with Report-Only. - Enable HSTS only after the whole site works on HTTPS, and start with a short
max-ageif unsure.
Copy-paste fixes
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Content-Security-Policy "frame-ancestors 'self'; upgrade-insecure-requests" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set Content-Security-Policy "frame-ancestors 'self'; upgrade-insecure-requests"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>add_action( 'send_headers', function () {
header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains' );
header( "Content-Security-Policy: frame-ancestors 'self'; upgrade-insecure-requests" );
header( 'X-Frame-Options: SAMEORIGIN' );
header( 'X-Content-Type-Options: nosniff' );
header( 'Referrer-Policy: strict-origin-when-cross-origin' );
} );import type { NextConfig } from "next";
const securityHeaders = [
{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" },
{ key: "Content-Security-Policy", value: "frame-ancestors 'self'; upgrade-insecure-requests" },
{ key: "X-Frame-Options", value: "SAMEORIGIN" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
];
const config: NextConfig = {
async headers() {
return [{ source: "/:path*", headers: securityHeaders }];
},
};
export default config;Common mistakes
- Adding a strict CSP in one go and breaking analytics, fonts or payments.
- Using
X-Frame-Options: DENYwhen you embed your own pages in iframes. - Setting headers in a meta tag. HSTS, X-Frame-Options and frame-ancestors only work as real HTTP headers.
Test your site now
Put your site against a competitor and see how many of these points you earn, and which fixes pay off first.