Content Security Policy (CSP)

How a Content-Security-Policy header limits which scripts can run on your site, and how to roll one out safely in report-only mode first.

What AuditX checks

The scan reads the Content-Security-Policy header, or a Content-Security-Policy meta tag when there is no header, and parses the policy per directive. A missing policy fails, and so does a policy sent only as Content-Security-Policy-Report-Only, because browsers report against that one but do not enforce it. 'unsafe-inline', 'unsafe-eval' or a * in the script sources is a warning, and the report says what each one lets through, unless a nonce or hash makes browsers ignore 'unsafe-inline'. 'unsafe-inline' for styles is noted as a smaller risk. A policy with no script-src or default-src, for example one that only sets frame-ancestors or upgrade-insecure-requests, is a warning as well: it does not restrict scripts at all, and the report names the directives it does set.

Why it matters

A CSP tells the browser which sources a page may load scripts, styles and frames from. If an attacker manages to inject a script tag through a form, a comment field or a compromised plugin, a strict policy stops that script from running.

A policy that allows unsafe-inline for scripts gives that protection away, because an injected inline script is exactly what it should block.

How to fix it

  1. List what your pages really load: your own domain, analytics, fonts, payment widgets, embeds.
  2. Publish the policy as Content-Security-Policy-Report-Only first. The browser then reports what it would have blocked without blocking anything. Watch the console or a report endpoint for a week.
  3. Replace inline scripts with files, or give each inline script a nonce or hash that the policy names.
  4. Switch the header name to Content-Security-Policy once the reports are clean.
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-RANDOM'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'

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.