CSP checker: what does this Content-Security-Policy actually block?
Paste a Content-Security-Policy header or <meta> tag. You get its weaknesses in plain words, which directive governs each kind of resource, and a tester that answers "would this script, style, image or inline code be allowed?" using the CSP Level 3 matching rules browsers follow. It runs in your browser; nothing is uploaded.
1. The policy
2. Findings
Which directive governs what
| Resource | Decided by | Sources |
|---|
3. Would it load?
Inline code and eval
The same checks from a terminal or CI
The CLI needs Node.js 20 or later and no install beyond the folder. It exits 1 on a high-severity finding or a blocked test, so it can gate a deploy.
curl -sI https://your-site.example | node cli.mjs
node cli.mjs --url https://your-site.example --test script https://cdn.example.com/lib.js
node cli.mjs "script-src 'self'" --inline script "alert('Hello, world.');" # prints the hash to add
Source and README: ventures/csp-policy-check. Run --url only against sites you own or are authorised to test.
Questions
Why is my script blocked when its host is in script-src?
The usual causes: the policy also has 'strict-dynamic', which makes browsers ignore host and scheme sources for scripts, so the <script> tag needs the nonce; a second policy (another header, or a comma in one header) blocks it, and every policy must allow a load; the source has a path without a trailing slash, which matches one file exactly; or the script is on a subdomain and the source names only the parent domain. Paste the policy above and test the URL to see which applies. The guide to the "Refused to execute inline script" error walks through the inline case.
Does 'unsafe-inline' still work if I add a nonce?
No. In CSP Level 2 and later, a nonce or hash source in the same list makes browsers ignore 'unsafe-inline'. Keeping it next to a nonce is a deliberate fallback for very old browsers, and modern browsers then run only the inline scripts carrying the nonce or matching a hash.
Which directives does a <meta> CSP ignore?
frame-ancestors, report-uri and sandbox have no effect in a <meta http-equiv="Content-Security-Policy"> element (CSP Level 3, section 3.3). Send them as a response header. A meta policy also applies only to content after the meta element.
Does a policy with no high findings mean my site is safe from XSS?
No. This tool reads the policy text; it cannot see your pages, whether nonces are really random per response, whether an allowed host serves JSONP or user uploads, or whether your own scripts pass untrusted strings to eval or innerHTML. A clean result says the policy avoids the specific weaknesses listed here, not that the site has no injection bugs.
What are the rules based on?
The matching follows the W3C Content Security Policy Level 3 draft: parsing (section 2.2.1), the fallback lists (section 6.8), and URL, nonce, hash and inline matching (sections 6.6 and 6.7). The strict-policy advice follows Weichselbaum, Spagnuolo, Lekies and Janc, "CSP Is Dead, Long Live CSP!" (ACM CCS 2016). Browsers differ from the draft at the edges; the README lists the cases this tool does not model.