Short answer: the error names the blocked URL and the directive that blocked it. Add that URL's origin to that directive (or to the specific directive the message says was missing). Don't add *, https: or 'unsafe-inline' to make it go away.
Read the message
Chrome's errors look like one of these. Older versions start with "Refused to…":
Refused to load the script 'https://cdn.example.com/widget.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Newer versions say the same thing a different way:
Loading the script 'https://cdn.example.com/widget.js' violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback. The action has been blocked.
Either way, there are four parts:
| Part | Here | What it tells you |
|---|---|---|
| What | the script | The kind of resource: script, stylesheet, image, font, frame, or a connection from fetch() |
| Where from | https://cdn.example.com/widget.js | The URL that was blocked. For inline code there's no URL; see below |
| Rule | script-src 'self' | The directive that decided, with its full value |
| Fallback note | script-src-elem wasn't set | Which directive the browser looked for first. Here there's no script-src-elem, so script-src decided |
For inline code, current Chrome starts with "Executing inline script", "Executing inline event handler" or "Applying inline style" (older versions: "Refused to execute inline script…"), and says a nonce, a hash or 'unsafe-inline' is needed. Blocked frames and form submissions say "The request has been blocked" instead.
Firefox and Safari word their messages differently. Firefox names the same directive and its value. Safari names the directive family, for example script-src even when script-src-elem applied, without its value.
Find the right directive
Each kind of request has its own directive, and most fall back to default-src when theirs isn't set:
| Blocked | Directive |
|---|---|
<script src> | script-src-elem, then script-src, then default-src |
Inline <script>, onclick | script-src-elem or script-src-attr, then script-src, then default-src |
| Stylesheets and inline styles | style-src-elem or style-src-attr, then style-src, then default-src |
| Images, favicons | img-src, then default-src |
| Fonts | font-src, then default-src |
fetch(), XHR, WebSocket, EventSource, sendBeacon() | connect-src, then default-src |
<iframe> on your page | frame-src, then child-src, then default-src |
| Your page inside someone else's frame | frame-ancestors (no fallback) |
frame-ancestors, form-action and base-uri don't fall back to default-src. When they aren't set, they allow everything.
Fix it
- Add the origin to the directive the message names. For the example above,
script-src 'self' https://cdn.example.com. Use the origin (https://cdn.example.com) or a narrower path, not a broad wildcard. - If you add a more specific directive, copy the old sources into it. Adding
script-src-elem https://cdn.example.commeansscript-srcno longer applies to<script>elements, so without'self'your own scripts break, and inline scripts need their nonces or hashes copied across too. The fallback note in the message tells you which directive was in use. - For inline code, use a nonce or a hash, not
'unsafe-inline'. See what 'unsafe-inline' does and what to use instead. - Check the policy you edited is the one that's being enforced. See below.
Still blocked after you fixed it?
- There may be two policies. A page can get policies from several headers and
<meta>tags, for example one from your app and one added by a CDN or framework. A request must be allowed by every policy, so loosening one doesn't help if another still blocks it. Look at the response headers in the Network panel, and for<meta http-equiv="Content-Security-Policy">in the HTML. 'strict-dynamic'is on. If the message notes that host-based allowlisting is disabled, host sources likehttps://cdn.example.comare ignored. Give the<script>tag the nonce, or add the script from a script that has one.- The rule is in a
<meta>tag.frame-ancestors,report-uriandsandboxare ignored in<meta>policies; they only work as headers. - It only reported. Messages from a
Content-Security-Policy-Report-Onlyheader are marked as report-only (current Chrome adds that the violation "has been logged", and older versions start with "[Report Only]"). Nothing was actually blocked, so the cause of a broken page is elsewhere. Report-only policies only work as headers, not in<meta>. - The browser cached the old page. Reload with the cache disabled (DevTools, Network, Disable cache) after changing a header.
Check before you deploy
Paste your policy into the CSP explainer, then use Test it with the blocked URL and resource type. It tells you which directive applies, whether it's allowed, and why. Try the fix there first, then deploy it as Content-Security-Policy-Report-Only if you want to be sure nothing else breaks.
