CSP Header Builder

Choose where scripts, styles, images and connections may come from, and copy a ready policy as a header, a meta tag or a config snippet. Warnings point out risky settings.

Runs in your browser. Nothing you type is uploaded.

Your numbers

Scripts

Other sources

Protections

Result

Your policy11 directives

Report-only mode: browsers report problems but block nothing. Switch to enforcing once reports are clean.

  • object-src 'none'
  • base-uri 'self'
  • No unsafe-inline scripts
  • No unsafe-eval
  • Clickjacking protection (frame-ancestors)
  • No wildcard sources
  • Meta tag limitsThe meta tag ignores frame-ancestors and reporting, and cannot run in report-only mode. Prefer the header.
HTTP header
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-{RANDOM_NONCE}'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests
HTML meta tag (always enforces, no report-only)
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'nonce-{RANDOM_NONCE}'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests">
nginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' 'nonce-{RANDOM_NONCE}'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests" always;
Netlify (_headers file)
/*
  Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-{RANDOM_NONCE}'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests
Vercel (vercel.json)
{
  "headers": [
    {
      "source": "/(.*)",
      "headers": [
        {
          "key": "Content-Security-Policy-Report-Only",
          "value": "default-src 'self'; script-src 'self' 'nonce-{RANDOM_NONCE}'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests"
        }
      ]
    }
  ]
}
  • Replace {RANDOM_NONCE} with a new random value on every response, and add the same nonce="..." attribute to your script tags. A fixed nonce gives no protection.

How it works

Directives
Each directive lists where one kind of content may load from. default-src is the fallback for anything not listed. Keywords like self and none need single quotes; the builder adds them if you forget.
Nonces
A nonce is a random value sent in the header and added to each script tag. Only scripts with the right nonce run, so injected scripts are blocked. 'strict-dynamic' then trusts scripts those scripts load.
Rolling it out
Start in report-only mode with a report URL, watch what would be blocked, fix or allow it, then switch to the enforcing header.

Questions

Header or meta tag?

Use the HTTP header when you can. The meta tag works on static hosts, but it cannot set frame-ancestors, send reports or run in report-only mode.

Why did my site break after adding CSP?

Something loads from a source you did not list, or an inline script has no nonce. Open the browser console: each blocked item names the directive to change.

Are the preset hosts complete?

They are a starting point. Analytics and payment providers change their domains, so check the provider's docs for their current CSP list before going live.

Get CapyLaunch Weekly

New indie launches and the week in AI tools and models, every Monday. Free, and you can unsubscribe anytime.

We send a confirm link first. Privacy

Your launch, this week. Free.

A reviewed listing, a permanent page with a link to your site, and feedback from makers who actually care.

Start my launch →or browse toolsFree to submit. Every listing is reviewed before it goes live.