Generator

CSP Header Generator

Build a Content Security Policy header by selecting your sources. The generator outputs a header value ready to paste into Nginx, Apache, Vercel, or Cloudflare — and includes the config block for your stack.

Click "Generate CSP" to build your policy.

What each directive controls

DirectiveControlsTip
default-srcFallback for all types not listedStart with 'self'
script-srcJavaScript files and inline scriptsAvoid unsafe-inline — use nonces
style-srcCSS files and inline stylesunsafe-inline usually required for CSS-in-JS
img-srcImagesAdd data: for base64 images
connect-srcfetch, XHR, WebSocket, EventSourceRequired for any API calls
font-srcFont filesGoogle Fonts needs fonts.gstatic.com
frame-ancestorsWho can embed your page in an iframe'none' blocks clickjacking
object-srcPlugins (Flash, Java)Always set to 'none'

Deploy in report-only mode first

Use Content-Security-Policy-Report-Only instead of Content-Security-Policy when first deploying. Violations appear in the browser console without blocking anything — letting you catch missing sources before enforcing.

If you have a live page and want to generate a CSP from what it actually loads, use CSPFixer instead — it scans your URL and builds the policy automatically.

Scan a live URL and auto-generate CSP → CSPFixer