Free tool

CSP & HTTP Security Headers Generator

Build an A+ Content-Security-Policy, HSTS, and Permissions-Policy header configuration with 1-click third-party presets and instant exports for Next.js, Vercel, Nginx, Cloudflare, and Apache.

CSP & HTTP Security Headers Generator: the tool

Baseline Architecture Presets:
Live Security Grade
Score: 96/100 (7 headers)
A+
Real-Time Security Audit
style-src uses 'unsafe-inline' (common for CSS-in-JS/Tailwind runtime styles). Remove it if you bundle static CSS.

1-Click Third-Party Service Allowlists

Appends exact domains to CSP

Content-Security-Policy Directives

Fallback fetch policy for all unlisted resource types
Allowed JavaScript origins & execution policies
Allowed CSS stylesheets & inline style rules
Allowed image sources (https:, data:, blob:, CDNs)
Allowed fetch(), XHR, WebSocket, and EventSource targets
Allowed webfont origins (WOFF2, Google Fonts)
Allowed embedded iframe origins (Stripe, YouTube, Turnstile)
Who is allowed to embed YOUR site in an iframe (clickjacking defense)
Legacy plugins (Flash/Java) — keep at 'none'
Restricts <base> element URL hijacking

HTTP Hardening Headers (HSTS, Permissions, COOP)

Platform Config Export

Target file: next.config.ts7 active headers
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  async headers() {
    return [
      {
        source: "/(.*)",
        headers: [
          { key: "Content-Security-Policy", value: "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https:; connect-src 'self'; font-src 'self' data:; frame-src 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; upgrade-insecure-requests" },
          { key: "Strict-Transport-Security", value: "max-age=63072000; includeSubDomains; preload" },
          { 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: "Cross-Origin-Opener-Policy", value: "same-origin" },
        ],
      },
    ];
  },
};

export default nextConfig;

Hardening a Next.js, SaaS, or fintech application for SOC 2 or enterprise security reviews?

DEESU implements nonce-based CSP middleware, edge WAF rules, and end-to-end web application security audits.

Schedule a Security Review

How it works

Why Content-Security-Policy (CSP) Is Your Strongest Defense Against XSS

Cross-Site Scripting (XSS) remains one of the highest-impact vulnerabilities in modern web applications. Even when frameworks like React, Vue, or Next.js escape HTML by default, a single unsafe dangerouslySetInnerHTML, compromised npm package, or third-party marketing tag can inject malicious JavaScript capable of exfiltrating session tokens, hijacking checkout forms, or skimming credit cards.

A strict Content-Security-Policy HTTP response header shifts security enforcement directly into the user's browser. By declaring an explicit allowlist for script-src, connect-src, frame-src, and object-src, the browser immediately refuses to execute injected inline scripts or beacon stolen data to unauthorized domains—turning a catastrophic account takeover into a blocked console violation.

Essential HTTP Security Headers Beyond CSP

A complete defense-in-depth header baseline pairs CSP with five lightweight response headers that neutralize entire classes of browser attacks with almost zero latency overhead:

  • Strict-Transport-Security (HSTS): Forces browsers to connect strictly over HTTPS for two years (max-age=63072000; includeSubDomains; preload), defeating SSL stripping on public Wi-Fi.
  • X-Frame-Options & CSP frame-ancestors: Prevents malicious sites from wrapping your dashboard or checkout page in a hidden iframe to trick users into unintended clicks (clickjacking).
  • X-Content-Type-Options: nosniff: Stops browsers from guessing MIME types on uploaded files (preventing an attacker from disguising JavaScript inside an image upload).
  • Referrer-Policy: Setting strict-origin-when-cross-origin prevents sensitive URL paths and query tokens from leaking to third-party sites in the HTTP Referer header.
  • Permissions-Policy & COOP: Explicitly revokes unused browser APIs like camera=(), microphone=(), and geolocation=(), while Cross-Origin-Opener-Policy: same-origin isolates your browsing context from cross-origin popups (Spectre mitigation).

Rolling Out CSP Safely Without Breaking Production Analytics or Checkout

The #1 reason teams abandon Content-Security-Policy is deploying a strict policy directly in enforcement mode and accidentally blocking Google Tag Manager, Stripe Elements, Google Fonts, or YouTube embeds. Always start by enabling Content-Security-Policy-Report-Only in staging or for your first week in production. In Report-Only mode, the browser logs every violation in DevTools without breaking live functionality.

Once your audit shows zero unexpected violations, switch back to the enforcing Content-Security-Policy header. Whenever you integrate a new SaaS widget or payment SDK, add only the exact hostnames required (such as https://js.stripe.com in script-src and frame-src) rather than falling back to wide * wildcards.

Deploying Security Headers Across Next.js, Vercel, Cloudflare, Nginx, and Apache

Unlike HTML <meta http-equiv> tags—which ignore frame-ancestors, X-Frame-Options, and Report-Only—true HTTP response headers must be emitted by your web server, CDN edge, or framework middleware. Static hosts like Cloudflare Pages and Netlify read a plain-text public/_headers file at deploy time; Vercel reads vercel.json; Next.js supports async headers() in next.config.ts (or dynamic per-request nonces in middleware.ts); and self-hosted Linux servers apply add_header ... always; in Nginx or Header always set in Apache.

FAQ

Questions, answered

Allowing 'unsafe-inline' in script-src permits any <script> tag or onclick= handler injected into your HTML to execute—defeating CSP's primary protection against Cross-Site Scripting (XSS). For production apps requiring inline scripts, generate a cryptographic per-request nonce in middleware (e.g. Next.js middleware.ts) or use SHA-256 script hashes.

Modern browsers prioritize CSP frame-ancestors over X-Frame-Options, so frame-ancestors 'none' is the canonical standard. However, keeping X-Frame-Options: DENY alongside it provides backwards compatibility with legacy clients and satisfies automated compliance scanners (like Mozilla Observatory and SecurityHeaders.com).

Only add includeSubDomains; preload once you are 100% certain that your root domain AND every single subdomain (including staging, mail, or internal portals) will serve valid HTTPS certificates permanently. Removing a domain from the Chrome HSTS Preload list takes months.

Cross-Origin-Opener-Policy: same-origin severs window.opener communication with cross-origin popup windows. If your app uses Google Sign-In popups, OAuth popups, or certain third-party payment popups, switch COOP to same-origin-allow-popups.

Place the _headers file inside your public/ directory (e.g. public/_headers). Vite automatically copies it to dist/_headers during npm run build, where Cloudflare Pages and Netlify automatically apply it to every HTTP response.

More free tools

Reply within 1 business day

Tell us what you're building.

Send the problem, not a polished brief. We'll tell you what it actually takes to ship it: stack, timeline and cost, before you commit to anything.