Tools / CSP evaluator

Content Security Policy (CSP) evaluator

Inspect the enforced CSP response header and flag common risky source expressions or missing defensive directives.

Common checks

This is a heuristic policy review, not an XSS test or proof of security. CSP Report-Only headers are not enforced and are not treated as an active policy.

What a CSP is actually for

A Content Security Policy is a second line of defence. It does not stop an injection bug from existing; it limits what an injected payload can do once it is on the page. Treating CSP as a substitute for output encoding and input validation is the most expensive mistake you can make with it — a policy is worth having precisely because the first line will eventually fail somewhere.

That framing matters when you read a result. A page with a strict policy and an XSS hole is still vulnerable; the policy just narrows what an attacker can reach. A page with no policy and no bugs is fine today and defenceless the moment a bug appears.

Why 'unsafe-inline' undoes most of the benefit

The headline reason to deploy CSP is to stop injected <script> from executing. script-src 'unsafe-inline' permits exactly that, which is why a policy containing it provides very little script protection no matter how long the rest of the header is. The same goes for 'unsafe-eval', which re-opens eval(), new Function() and string arguments to setTimeout.

There are two supported ways out, and both require touching the application:

One wrinkle catches people out: in modern browsers, specifying a nonce or hash causes 'unsafe-inline' to be ignored for that directive. That is deliberate, and it is how you keep a fallback for very old browsers without weakening current ones.

Allowlists age badly

Listing CDNs and vendor domains feels safe and usually is not. If any allowlisted host serves a JSONP endpoint, an unrestricted file upload, an old copy of AngularJS, or any library with a usable gadget, an attacker can route an injection through it and your policy approves the request. Published research has repeatedly found that a large share of real-world allowlists contain at least one bypassable host.

This is the reasoning behind strict-dynamic: trust scripts you explicitly nonce or hash, let those scripts load their own dependencies, and stop trying to enumerate hostnames. It is harder to retrofit, and it is the direction a serious policy eventually goes.

The directives people forget

Rolling one out without breaking the site

Deploy as Content-Security-Policy-Report-Only first with a report-uri or report-to endpoint, leave it long enough to cover real traffic rather than your own testing, then read the reports before you enforce. Expect noise: browser extensions generate violations you cannot fix and should not chase.

Enforce in stages. Promote the directives whose reports are clean and leave the rest reporting — a policy that is half enforced and half measured beats one that is entirely aspirational. Be aware this tool reads the enforced header only; a Report-Only policy is deliberately not counted as protection, because it blocks nothing.

Related checks: security headers analyzer and CORS policy checker. If you are introducing a policy to an application that already relies on inline script, we test the injection paths a CSP is meant to contain.

Frequently asked questions

How do I add a Content Security Policy without breaking my site?

Start with the Content-Security-Policy-Report-Only header. Browsers then report what the policy would block without blocking it. Fix or allow each legitimate source, then switch to the enforcing header.

Should I use nonces or hashes?

Nonces suit pages generated by a server: a new random value on each response, added to every <script> tag. Hashes suit static pages whose inline scripts never change. Both let you drop 'unsafe-inline'.

Can I set a CSP in a meta tag?

Yes, with <meta http-equiv="Content-Security-Policy">, but some directives — frame-ancestors, report-uri and sandbox — only work as an HTTP header. The header is the better choice whenever you control the server.

Why is my Report-Only policy not graded?

A Report-Only policy is not enforced, so it gives visitors no protection yet. The evaluator grades only the policy browsers actually apply.