Tools / CSP Generator & Evaluator

CSP Generator & Evaluator.

Check a Content-Security-Policy for XSS bypasses, or build one from a preset with ready-to-paste server snippets.

Runs in your browser

Paste the header value or the whole Content-Security-Policy line.

Used in generate mode. strict = nonce + 'strict-dynamic'.

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result
Findings
Summary
Normalized policy
Directives
Server snippets

About CSP Generator & Evaluator

The CSP Generator & Evaluator helps you write a Content-Security-Policy that actually stops cross-site scripting. In evaluate mode, paste the header from your site and every directive is checked against the mistakes that make a policy easy to bypass: 'unsafe-inline' without a nonce or hash, 'unsafe-eval', wildcards and bare https: in script-src, hosts such as cdnjs.cloudflare.com or www.google.com that serve JSONP or AngularJS and are known bypasses, keywords written without quotes (self instead of 'self'), short nonces, malformed hashes, and missing object-src, base-uri and frame-ancestors. Findings are sorted by severity and each one says why it matters. For example, script-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com gets a high finding for 'unsafe-inline', a medium one for the CDN, and a high one because object-src is missing. In generate mode, start from a starter allowlist or Google's recommended strict policy ('nonce-…' plus 'strict-dynamic'), override any directive, add a report URI, and copy the result as an HTTP header, a Report-Only header, nginx add_header, Apache Header set or an HTML meta tag. A frequent error is putting frame-ancestors or report-uri in a meta tag, where browsers ignore them; the snippet leaves them out. Roll out with Report-Only first. Everything is evaluated in your browser.

How to Use

  1. Choose evaluate and paste your current policy, or choose generate and pick a preset.
  2. Read the findings table, starting with the high-severity rows.
  3. Copy the normalized policy or a server snippet and deploy it as Report-Only first.

Frequently Asked Questions

What is a strict CSP?

A policy that trusts scripts by nonce or hash instead of by host, usually script-src 'nonce-RANDOM' 'strict-dynamic'; object-src 'none'; base-uri 'none'. It avoids the host allowlist bypasses that most CSPs suffer from.

Why is 'unsafe-inline' only "info" in some policies?

When a nonce or hash is present, CSP Level 2+ browsers ignore 'unsafe-inline'. It is kept only so very old browsers still run the page.

Where do I get the nonce?

Your server must generate a new random value (at least 128 bits, Base64) for every response and put it in both the header and each script tag. The {RANDOM} placeholder in the preset must be replaced.

Is my policy sent to a server?

No. Parsing and evaluation run in your browser, and the page makes no network requests while you use it.

Related Tools