// SECURITY GUIDE · HTTP HEADERS
HTTP Security Headers
// WHAT THEY ARE
HTTP security headers are directives your server sends with every response. They tell the browser how to behave: what scripts to trust, whether to allow iframes, how to handle MIME types. They cost nothing to add and block entire classes of attacks.
// WHY IT MATTERS
XSS attacks inject malicious scripts into your pages. Clickjacking embeds your site in an iframe and tricks users into clicking hidden buttons. MIME sniffing lets browsers execute files as a different type than intended. Headers stop all of these at the browser level. Before any damage is done.
// WHAT WE CHECK
unsafe-inline in script-src.max-age ≥ 31536000 (1 year).DENY or SAMEORIGIN.nosniff.Referer header. Recommended: strict-origin-when-cross-origin.// HOW TO FIX: NEXT.JS
// next.config.ts
async headers() {
return [{
source: "/(.*)",
headers: [
{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=()" },
],
}];
}For CSP with Next.js, use a nonce-based approach via proxy.ts (middleware). See the Next.js CSP docs.
// HOW TO FIX: NGINX
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;