CSP Generator

Pick directives, add sources, and get a Content-Security-Policy header. The part worth having is the review underneath it. A policy containing 'unsafe-inline' in script-src blocks almost nothing — inline execution is exactly what an XSS payload needs — and it is the commonest mistake in this area precisely because nothing breaks and no errors appear, so people assume they are covered. That gets flagged. So does the assumption that a strict default-src covers everything: frame-ancestors, base-uri and form-action do not fall back to it, and are simply unenforced if you leave them out. An unset base-uri lets an injected <base> tag redirect every relative URL on your page. Report-only is on by default, because shipping an untested policy in enforcing mode is how you take a site down.

Directives with no default-src fallback

DirectiveIf you omit it
frame-ancestorsAnyone can frame your page — clickjacking
base-uriAn injected <base> can redirect every relative URL
form-actionForms can be made to submit anywhere
script-srcFalls back to default-src — covered
img-srcFalls back to default-src — covered

When to use it

  1. Write a first CSP for a site that has none.
  2. Check whether an existing policy actually protects anything.
  3. Work out which directives you are missing.
  4. Add a CDN or analytics domain to an existing policy.
  5. Produce a report-only policy to test before enforcing.

How to Use

  1. Choose a directive and add the sources it should allow.
  2. Read the review for anything that weakens the policy.
  3. Deploy the report-only header first, then enforce.

Features

  1. Every common directive with a plain explanation
  2. Keyword and custom source values
  3. Severity-rated warnings for weakening values
  4. Flags missing directives that have no fallback
  5. Report-only and enforcing output
  6. Header and meta-tag forms, with the meta caveat stated

FAQs

What does a Content-Security-Policy do?

It tells the browser which sources of script, style, images and other content are allowed to load and run on your page. Anything not permitted is blocked, which turns most cross-site-scripting bugs from an exploit into a console error.

Why is 'unsafe-inline' such a problem?

Because inline script execution is the mechanism of almost every XSS attack. Allowing it means an injected <script> tag runs exactly as it would with no policy at all. The site keeps working, nothing logs an error, and the header provides a false sense of protection. Use a nonce or a hash for the inline scripts you genuinely need.

Does default-src cover everything?

No, and this catches people out. It is the fallback for the fetch directives — script-src, img-src and their relatives — but frame-ancestors, base-uri and form-action ignore it completely. Leave those out and they are not enforced, however strict your default-src is.

Should I start with report-only?

Yes. Content-Security-Policy-Report-Only applies the policy and reports violations without blocking anything, so you can find what your own site would break before it breaks for visitors. Switch to the enforcing header once the reports are quiet.

Can I use the meta tag instead of a header?

Mostly, but not entirely. frame-ancestors is ignored in a meta tag, so clickjacking protection only works as a real HTTP header. If you can only set a meta tag, add X-Frame-Options as well.

What is 'strict-dynamic'?

It lets a script you have already trusted, via nonce or hash, load further scripts, while ignoring host allowlists. It is the modern approach for applications that load code dynamically, and it makes long CDN allowlists unnecessary.

Technical Details

Building the header string is trivial; the value is in what the tool refuses to let you do quietly. A policy containing 'unsafe-inline' in script-src provides essentially no cross-site-scripting protection, because inline script execution is exactly what an XSS payload needs — and it is the most common misconfiguration by a wide margin, precisely because it produces no console errors and no visible breakage. Someone adds the header, sees the site working, and believes they are protected. That is flagged as high severity, as is 'unsafe-eval' and a bare wildcard. The same value in style-src is flagged too, but as medium, because injected CSS can leak data through attribute selectors and background URLs without being able to execute code. The other thing the tool tracks is which directives actually fall back to default-src, because three of the most important ones do not: frame-ancestors, base-uri and form-action are each ignored entirely if omitted, no matter how strict default-src is. People assume a tight default-src covers them, and it does not — an unset base-uri lets an injected <base> tag redirect every relative URL on the page. Missing ones are reported. The meta-tag output carries its own caveat, since frame-ancestors is ignored when a policy is delivered that way and only works as a real header. Report-only is the default, because deploying an untested policy in enforcing mode breaks sites.

Security Tools

Security Tools

  • security.txt Generator
  • AES Encryption
  • Bcrypt Hash Generator
  • BIP39 Mnemonic Generator
  • CVSS Calculator
  • CORS Debugger
  • RSA Key Generator
  • SRI Hash Generator