Content-Security-Policy enforcement on the live page

How the scan tests whether your Content-Security-Policy really blocks an injected inline script in a real browser, and why some results are only a note.

What AuditX checks

This check runs only when your page sends a Content-Security-Policy header. The scan opens the page in its own headless Chrome, adds one small inline script element to the page through the DOM, the way an injected script would land, and reads back whether that script ran and whether the browser reported a policy violation. The script only sets one property in our own browser tab; nothing is submitted to your site and no other request is made. It passes when your policy should block an unlabeled inline script and the script did not run. It fails when the policy should have blocked it but the script ran anyway. It is an info note when the policy text itself already allows inline scripts, for example with 'unsafe-inline' or with no script-src or default-src at all, because the Content-Security-Policy finding already grades that. It is also an info note when the policy uses 'strict-dynamic': under that keyword a script that page code adds through the DOM is allowed by design, so this test cannot tell whether injected markup in the HTML would be blocked. When the browser test could not run, the result is marked as not measured.

Why it matters

A Content-Security-Policy is one of the strongest defenses against cross-site scripting, but only if the browser actually applies it. A typo in a directive, a header that only some responses carry, or a proxy or CDN that rewrites headers can all leave a policy that looks right in the header text but protects nothing.

Reading the header can never prove enforcement. Running a script in a real browser can.

A fail counts in full toward the security score. The info notes and an unmeasured result cost nothing, although an unmeasured check caps the security score at 79.

How to fix it

  1. Confirm that the header is sent on every HTML response, not only the homepage or only cached responses.
  2. Check the directive names and values for typos. A browser ignores a directive it does not recognize, and a policy with a broken script-src may fall back to allowing scripts.
  3. Check whether a proxy, CDN, security plugin or service worker in front of the site strips or rewrites the header before it reaches the browser. Compare the header you configured with the one the browser receives in its developer tools.
  4. If you use 'strict-dynamic', keep a nonce or hash on every script tag you write yourself. That setup is what Google recommends, and the info note is expected.
Content-Security-Policy: script-src 'nonce-r4nd0m' 'strict-dynamic'; object-src 'none'; base-uri 'none'

Does your site pass this check? A free scan runs it with every other check and shows the result in about a minute.

Scan my site

Sources

Related checks

Last reviewed 2026-11-13.