Skip to main content

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.

Frequently asked questions

What does a Content-Security-Policy header actually do?
CSP tells the browser which sources are allowed to load scripts, styles, images, fonts, and other resources on your page. It's a defense-in-depth measure against cross-site scripting (XSS) and data injection attacks — even if an attacker manages to inject a <script> tag, the browser refuses to execute it if its source isn't allowed by the policy.
Why does the tool warn me about 'unsafe-inline'?
'unsafe-inline' allows inline <script> and <style> tags and inline event handlers to run, which defeats a large part of what CSP protects against — an attacker who can inject HTML can also inject an inline script. It's sometimes unavoidable for legacy code, but the warning is there so you make that trade-off knowingly rather than by accident.
How do I actually apply this header?
Send it as an HTTP response header named Content-Security-Policy from your server or CDN configuration, or add it as a <meta http-equiv="Content-Security-Policy" content="..."> tag in your HTML (with some restrictions — frame-ancestors and a few other directives only work via the HTTP header, not the meta tag).
Is my configuration sent anywhere?
No — the header string is assembled entirely in your browser from the rules you enter. Nothing is sent to a server.
Will this tell me if my policy is missing a domain my site actually needs?
No. This tool only checks the syntax and flags a handful of well-known footguns ('none' combined with other sources, unsafe-inline, unsafe-eval, a wildcard '*') — it has no visibility into what your live page actually loads. Deploy the policy in Content-Security-Policy-Report-Only mode first and check real browser console violations before enforcing it, so you catch missing domains before anything breaks.
Why did a CSP header break my site?
A Content Security Policy lists which sources may load scripts, styles, fonts and images. If your site uses something the list does not allow, such as an analytics script or an inline style, the browser blocks it and part of the page breaks. Open the browser console: each blocked item is named there, so add only that source. Start with Report-Only mode to see problems without breaking the site.

Related tools

More Security & Auth

View all Security & Auth tools →