Home/Tools/Next.js Security Headers & CSP Generator
100% Free Developer Utility

Next.js Security Headers & CSP Generator

Almost every AI starter ships with zero security headers. That leaves your app vulnerable to clickjacking and script injection. Select your third-party integrations below to generate clean, battle-tested headers in seconds.

Allowed Third Parties & Services

Browser Defense Policies

What Each Header Actually Protects

Content-Security-Policy: Whitelists exact domains your frontend can fetch scripts and styles from, killing rogue injected scripts in their tracks.

X-Frame-Options: Stops scammers from embedding your login or checkout screen inside a transparent iframe to steal user clicks.

Permissions-Policy: Disables unauthorized camera, microphone, and geolocation hardware access by default.

Config file: next.config.ts42 lines
import type { NextConfig } from 'next';

const securityHeaders = [
  {
    key: 'Content-Security-Policy',
    value: "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://js.stripe.com https://www.googletagmanager.com https://us.i.posthog.com https://eu.i.posthog.com https://va.vercel-scripts.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' blob: data: https:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.stripe.com https://*.supabase.co wss://*.supabase.co https://*.google-analytics.com https://us.i.posthog.com https://eu.i.posthog.com https://vitals.vercel-insights.com; frame-src 'self' https://js.stripe.com https://hooks.stripe.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests",
  },
  {
    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=(), browsing-topics=()',
  },
  {
    key: 'Strict-Transport-Security',
    value: 'max-age=63072000; includeSubDomains; preload',
  },
];

const nextConfig: NextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: securityHeaders,
      },
    ];
  },
};

export default nextConfig;

How to Apply in Next.js

  1. Paste the snippet into your project root as next.config.ts.
  2. Run npm run build locally to verify there are no syntax conflicts.
  3. Deploy to production. You can inspect your live response headers in Chrome DevTools under the Network tab.
Want to test your live production deployment?

Headers are only one part of launch readiness. The Founder Pass ($15 one-time) analyzes your live headers, repository secrets, and 106 other launch criteria in minutes.