01
Silence is a refusal
A directive that is not written falls back to default-src. What neither names is blocked. One exception: without default-src, an unnamed directive is not restricted at all, which is why an empty policy is worse than none.
Pikkola Policy Studio, tool No. 43
Choose one directive at a time instead of typing the line, read a policy you already have to see what it really allows, and hash the one inline script that has to stay. The result leaves as a header, a meta tag or a server rule. Nothing leaves this tab.
The policy
Each card is a directive and each chip is a source it allows. What the browser is told is only what the chips say: a directive you leave out falls back to default-src, and what default-src does not name is closed.
Enforce: the browser blocks what the policy does not allow.
No directives yet. Add one, or start from a preset above.
A source is a keyword in single quotes, a scheme such as https:, or an origin such as https://cdn.example.com. Ports, paths and wildcards are allowed in an origin.
A policy you already have
A plugin wrote it, or a colleague did. Paste the header value, the whole header line or a meta tag: the directives are listed as the browser reads them, and each setting that gives the most away comes with the change that fixes it.
Report-Only is read the same way. It is shown as a note rather than a finding, because such a header blocks nothing by design.
100 / 100
| Directive | Sources |
|---|
A note is not always a mistake. It is what a browser will do with the line, and what it costs.
The inline block
A directive that carries a hash may skip 'unsafe-inline' and still let that exact block run. The hash is computed here with the browser's own crypto over the bytes you paste, so whitespace and quoting have to match the page.
The tags, the line breaks and the indentation are not part of the value; everything between them is.
Value for the policy
'sha256-…'
With a hash in the directive, 'unsafe-inline' in the same directive stops being applied. That is the intended way off inline code, and it is why the two are often seen together.
How it is read
01
A directive that is not written falls back to default-src. What neither names is blocked. One exception: without default-src, an unnamed directive is not restricted at all, which is why an empty policy is worse than none.
02
An origin matches only itself, scheme and port included. A scheme source such as https: matches any host over https. A path in an origin is a prefix. 'none' means nothing, and it cannot be mixed with anything else.
03
A nonce, a hash or 'strict-dynamic' lets one inline block through. Without one of them the only option is 'unsafe-inline', which lets through any script that gets into the page, including the one an attacker adds.
| Directive | What it decides | The value to start from |
|---|---|---|
| default-src | Every fetch not covered by a directive of its own | 'self' |
| script-src | Scripts, and the inline blocks a nonce or hash names | 'self' |
| style-src | Stylesheets, and inline style attributes | 'self' |
| img-src | Images, including those in CSS | 'self' data: |
| connect-src | fetch, XHR, WebSocket and EventSource | 'self' |
| frame-ancestors | Which pages may embed this one; the successor to X-Frame-Options | 'none' |
| base-uri | What a <base> tag may point at | 'none' |
| form-action | Where a form may submit, after any redirect | 'none' |
| object-src | Plug ins: Flash, Java, and the rest of a shorter list every year | 'none' |
| report-to | Where a violation report is sent; sends nothing on its own | csp-endpoint |
Send it as Content-Security-Policy-Report-Only first. The browser then blocks nothing and reports what it would have blocked, so the missing hosts can be collected for a week before the switch. The mode is in the builder, and the header name follows it.
That is how the specification is written. Once a directive carries a nonce, a hash or 'strict-dynamic', browsers ignore 'unsafe-inline' in that directive. It is the safe way to leave inline scripts behind: the word stays for old browsers that do not know nonces.
A production build does not. Development builds use eval for the hot reload and the error overlay. If the production policy still asks for it, the build being served is not the production one.
A header, when you can send one. The meta tag cannot carry frame-ancestors, report-to, sandbox or upgrade-insecure-requests, and a policy in the body is read after part of the page has been parsed.
A _headers file is read on a git build. A Direct Upload ignores it, so the policy has to be added to the response by a Worker or a Transform Rule. The _headers tab writes the block, and the raw header suits a Worker as it is.
Yes. The hash covers the bytes between the tags exactly, so a changed space or timestamp gives a different value and the old hash stops matching. A page that inlines a build id needs a nonce instead of a hash.
No. It is read in this tab and kept in this browser's local storage so a reload does not lose the work. The page's own content policy sets connect-src to none, so a request could not leave even if one were attempted.