What does 'Refused to load the script because it violates the following Content Security Policy directive' mean?
Your Content-Security-Policy doesn't list the script's origin in script-src (or default-src), so the browser refused to run it. Add that exact origin, or use a nonce or hash for inline code. Don't add *, https: or 'unsafe-inline', which switch most of the CSP's protection off.
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
Refused to load the script 'https://js.example-cdn.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.Why it happens
- You added a new third-party script (analytics, payments, chat widget) after writing the CSP.
- The script loads more scripts from another domain.
- Inline
<script>blocks with no nonce or hash.
How to fix it
- Read the blocked URL from the console and add only that origin to
script-src. - For inline scripts, generate a per-request nonce and put it on the tag and in the header.
- Roll out changes with
Content-Security-Policy-Report-Onlyfirst, then enforce.
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m' https://js.example-cdn.com; object-src 'none'; base-uri 'self'; frame-ancestors 'none'Check it's fixed
Reload with the console open. There should be no CSP violations, and the page should still block an injected <script src="https://evil.example/x.js"> in a test.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
Should I just remove the CSP?
No. CSP is what stops an injected script from stealing sessions or keys from your users.
Where do I set CSP in Next.js or Vite apps?
In the host's response headers (for example next.config.js headers or middleware), or a <meta http-equiv> tag. Headers are preferred, and frame-ancestors only works as a header.
How do I check my policy?
Paste it into Google's CSP Evaluator, or run ProofForge's free security-headers check against your live URL.