Next.js Security Headers
Configure Next.js App Router security headers in `next.config.mjs` with HSTS, X-Content-Type-Options, Permissions-Policy, and strict CSP guidance for hydration scripts.
Generate a production-ready Cloudflare Pages `_headers` file with strict CSP, 25/25 ReadyCheck header score, HSTS preload, and immutable `/assets/*` caching.
HTTP Headers: 17/17 pts · TLS/CAA/security.txt: 8/8 pts · COOP/CORP Hardened
/* Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests Strict-Transport-Security: max-age=31536000; includeSubDomains; preload X-Content-Type-Options: nosniff X-Frame-Options: DENY Referrer-Policy: strict-origin-when-cross-origin Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=() Cross-Origin-Opener-Policy: same-origin Cross-Origin-Resource-Policy: same-origin /assets/* Cache-Control: public, max-age=31536000, immutable
Verify your deployed CSP, HSTS preload, 301 HTTP→HTTPS redirect, DNS CAA, security.txt, DMARC, and AI search readiness in seconds — or grab the $49 ReadyCheck Fix Pack for tailored config bundles.
# Place _headers at the root of your build output directory (e.g., dist/_headers) # Cloudflare Pages automatically applies rules without Workers compute cost. npx wrangler pages deploy dist --project-name=your-site curl -sI https://example.com | grep -iE "content-security-policy|strict-transport-security|x-frame-options|permissions-policy"
/.well-known/security.txt after deploy.
Configure Next.js App Router security headers in `next.config.mjs` with HSTS, X-Content-Type-Options, Permissions-Policy, and strict CSP guidance for hydration scripts.
Generate valid `vercel.json` header arrays for Edge Network routes with HSTS preload, Permissions-Policy, Referrer-Policy, and clickjacking protection.
Copy-paste hardened Nginx `server {}` block directives using `always` so 4xx/5xx error responses also emit HSTS, CSP, nosniff, and frame protection.
Generate a compliant Netlify `_headers` file for static sites and Edge Functions with strict CSP, HSTS preload, Referrer-Policy, and Permissions-Policy.
Protect Astro static builds and SSR adapters (Cloudflare, Vercel, Node) with strict `script-src 'self'`, zero inline event handlers, and 25/25 security headers.
Configure strict CSP and HTTP security headers for client-side Vite bundles hosted on Cloudflare Pages, Netlify, Vercel, or Nginx without breaking modulepreload.
With HTTPS + 301 redirect + CAA + security.txt active, this Cloudflare Pages preset scores 25/25 (17/17 from HTTP headers alone). Strict script-src 'self' earns the full 5/5 CSP points.
Cloudflare Pages reads `_headers` from your published build output folder (`dist/_headers` or `public/_headers`), NOT the repository root if you build into `dist/`.
Enter exact origins like https://api.yourdomain.com into the Custom connect-src or script-src fields above. Never add wildcard * or 'unsafe-eval', and verify your live deployment on audit.runglab.dev.