CSP Header Generator
Free CSP generator: build a Content-Security-Policy header from the sources you allow and read what it does. Runs in your browser.
Directives
Generated header
Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)
Free CSP Header Generator
Build a Content-Security-Policy header visually by adding directives and allowed sources, with live warnings about common misconfigurations. This CSP generator builds a Content-Security-Policy header from the sources you allow. It helps frontend and security teams design a Content-Security-Policy header that reduces script, style, and resource injection risk.
Why configure a Content-Security-Policy
CSP is one of the most effective browser-enforced defenses against cross-site scripting: instead of trying to sanitize every possible way an attacker might inject a script, you declare up front exactly which origins are allowed to supply scripts, styles, images, fonts, and other resources, and the browser blocks everything else — including inline scripts unless explicitly allowed. Getting the policy right by hand is fiddly, since each directive has its own syntax and a single typo can silently allow more than intended or break legitimate functionality.
How to use this generator
Add a directive, choose or type the sources it should allow, and use the quick-add buttons for common keywords like 'self' and 'none'. The tool flags common issues as you go — combining 'none' with other sources, allowing 'unsafe-inline' or 'unsafe-eval', or wildcarding a directive to any origin — then copy the finished header value into your server configuration.
Common use cases
- Drafting a starting CSP for a new project before tightening it based on real console violation reports
- Reviewing an existing policy for accidental use of unsafe-inline or unsafe-eval
- Working out the right script-src value when adding a new third-party analytics or widget script
- Documenting the intended security header configuration for a code review or security audit
Worked example
The default rules (default-src 'self', script-src 'self', style-src 'self', img-src 'self' data:) assemble cleanly into default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: with no warnings. Change script-src's sources to 'self' 'unsafe-inline' instead, and the header updates to include it while a warning appears: "script-src" allows 'unsafe-inline', which permits inline scripts/styles and weakens XSS protection. The tool still generates the header either way — the warning is advisory, not a block.
Common mistakes and edge cases
- This tool checks syntax and a handful of known footguns — it has no idea what your live page actually loads. It can't tell you that you forgot to allow a domain your site genuinely needs; only testing in Content-Security-Policy-Report-Only mode against the real page can catch that.
- Combining
'none'with any other source in the same directive triggers a warning, since'none'is only meaningful as the sole value — the header is still generated with both values present, which browsers may not interpret the way you intended. frame-ancestors(and a few other directives) only take effect via the actual HTTP response header, not a<meta http-equiv>tag — copying the generated header into a meta tag silently drops that protection for those specific directives.
Everything is assembled locally in your browser — no part of your configuration is sent to a server.