Pikkola Policy Studio, tool No. 43

The header a browser obeys first.

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.

12
directives to set
4
output formats
0
requests sent

The policy

One directive at a time

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.

Start from
Mode

Enforce: the browser blocks what the policy does not allow.

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

Paste it and see what it allows

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.

A+

100 / 100

Directive Sources

Findings

    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 hash for one inline script

    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

    Three things decide what gets through

    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.

    02

    The source list decides

    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

    Inline needs a name of its own

    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.

    What each directive decides
    Directive What it decides The value to start from
    default-srcEvery fetch not covered by a directive of its own'self'
    script-srcScripts, and the inline blocks a nonce or hash names'self'
    style-srcStylesheets, and inline style attributes'self'
    img-srcImages, including those in CSS'self' data:
    connect-srcfetch, XHR, WebSocket and EventSource'self'
    frame-ancestorsWhich pages may embed this one; the successor to X-Frame-Options'none'
    base-uriWhat a <base> tag may point at'none'
    form-actionWhere a form may submit, after any redirect'none'
    object-srcPlug ins: Flash, Java, and the rest of a shorter list every year'none'
    report-toWhere a violation report is sent; sends nothing on its owncsp-endpoint

    Questions

    Will a strict policy break my site?

    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.

    Why does 'unsafe-inline' stop working when I add a nonce?

    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.

    Does React need 'unsafe-eval'?

    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.

    Header or meta tag?

    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.

    Where does it go on Cloudflare Pages?

    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.

    Do the hashes change when the page changes?

    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.

    Is the policy I paste sent anywhere?

    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.