Workflow Tools Control Yard

Home / Web

Content-Security-Policy checker

Paste a Content-Security-Policy: the header line, its value, or the meta element. The page reads it as CSP Level 3 does, shows which directive each kind of resource falls back to, flags what lets injected scripts run and what is left open, and writes the lines for Apache, nginx and a meta element.

Sending the header

Apache: with always, the header also goes out with error pages and with redirects that Apache makes itself; without it, only with successful responses. nginx: without always, add_header adds the header only to responses such as 200, 301 and 304, not to error pages; with it, to every response. In nginx, an add_header line in a location block means that none of the add_header lines of the server block apply there, so the policy must be repeated (nginx 1.29.3 and later can merge them with add_header_inherit merge;); a $ in the value starts a variable. To try a policy first, send it as Content-Security-Policy-Report-Only: the browser blocks nothing, and with report-to or report-uri it reports what it would have blocked.

A nonce must be new in every response and should be at least 128 bits from a secure random generator; each script element carries the same value in its nonce attribute. That is the work of the application, not of a static header line.

Which directive each kind of resource uses

The browser takes the first of these directives that the policy has. A kind with none of them is not restricted. base-uri, form-action and frame-ancestors have no fallback: default-src does not cover them.

Kind of resourceDirectives, in the order used
Scripts: script elements and filesscript-src-elem, then script-src, then default-src
Inline event handlers, such as onclickscript-src-attr, then script-src, then default-src
Style sheets and style elementsstyle-src-elem, then style-src, then default-src
Style attributesstyle-src-attr, then style-src, then default-src
Workersworker-src, then child-src, then script-src, then default-src
Connections from scriptsconnect-src, then default-src
App manifestsmanifest-src, then default-src
Plugins: object and embedobject-src, then default-src
Framesframe-src, then child-src, then default-src
Audio, video and text tracksmedia-src, then default-src
Fontsfont-src, then default-src
Imagesimg-src, then default-src
The base elementbase-uri
Where forms are sentform-action
Pages that may frame this oneframe-ancestors

Directives

DirectiveWhat it controls
default-srcThe fallback for the fetch directives that are not set (see the order below).
child-srcFrames and workers: the fallback for frame-src and worker-src.
connect-srcWhere scripts may connect: fetch(), XMLHttpRequest, EventSource, sendBeacon() and the ping of a link, and WebSocket connections.
font-srcWhere fonts may load from.
frame-srcWhat may load in the page's frames.
img-srcWhere images may load from.
manifest-srcWhere app manifests may load from.
media-srcWhere video, audio and their text tracks may load from.
object-srcWhere plugin content (object and embed) may load from. Set it to 'none'.
script-srcWhere scripts may load from and which inline scripts and event handlers may run; also whether eval() and the like may run.
script-src-elemScript elements and script files; event handlers are left to script-src-attr.
script-src-attrInline event handlers, such as onclick.
style-srcWhere style sheets may load from and which inline styles may apply.
style-src-elemStyle sheets and style elements: every style except style attributes.
style-src-attrStyle attributes.
worker-srcWorkers, shared workers and service workers.
webrtcWhether WebRTC connections may be made: 'allow' or 'block'.
base-uriWhat the page's base element may set as its base address. default-src does not cover it.
sandboxPuts the page in an HTML sandbox, as if it were in a sandboxed iframe. Ignored in a meta element.
form-actionWhere the page's forms may be sent. default-src does not cover it.
frame-ancestorsWhich pages may show this page in a frame, iframe, object or embed. default-src does not cover it, a meta element cannot set it, and it takes the place of X-Frame-Options.
report-uriWhere to send violation reports. Deprecated: use report-to. Ignored where report-to is present, and in a meta element.
report-toThe name of the reporting endpoint that gets the violation reports.
upgrade-insecure-requestsThe browser loads the page's http addresses over https instead.
block-all-mixed-contentMixed content that cannot be upgraded to https is now always blocked, so this directive does nothing.
require-trusted-types-forWith 'script': the DOM XSS injection sinks take only Trusted Types values, not plain strings.
trusted-typesWhich Trusted Types policies the page may create, by name; 'none' for none, 'allow-duplicates' to allow one name twice.

Keywords

Keywords go in single quotes: self without them is a host named self. Besides keywords, a source can be a scheme (https:), a host (cdn.example.com, *.example.com, https://example.com/js/), * (any http or https address), a nonce ('nonce-...') or a hash ('sha256-...'). A host with letters outside ASCII is written in Punycode, and of IP addresses only 127.0.0.1 ever matches.

KeywordMeaning
'self'The page's own origin: its scheme, host and port.
'unsafe-inline'Allows inline scripts or styles and inline event handlers. Ignored when a nonce or a hash is listed with it, and for scripts when 'strict-dynamic' is.
'unsafe-eval'Lets scripts turn strings into code: eval(), Function(), and setTimeout() or setInterval() given a string.
'wasm-unsafe-eval'Lets the page compile and run WebAssembly.
'strict-dynamic'For scripts: host and scheme sources, 'self' and 'unsafe-inline' are ignored, and scripts that a nonced or hashed script adds are allowed.
'unsafe-hashes'Lets the listed hashes match event handlers, style attributes and javascript: links too; safer than 'unsafe-inline' for a page that cannot drop its event handlers.
'report-sample'Violation reports for inline content carry a sample of it.
'trusted-types-eval'Allows eval() and the like only while Trusted Types are required for scripts.
'unsafe-allow-redirects'In the grammar of CSP Level 3, which does not describe it yet.
'report-sha256'For each script the page loads, a report with its SHA-256 hash goes to the reporting endpoint; 'report-sha384' and 'report-sha512' do the same with those hashes.
'report-sha384'As 'report-sha256', with SHA-384.
'report-sha512'As 'report-sha256', with SHA-512.
'unsafe-webtransport-hashes'Allows WebTransport connections made with a list of certificate hashes, which are blocked without it.

Sources

More Web tools