# What does 'Refused to load the script because it violates the following Content Security Policy directive' mean?

**Short answer:** 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

```text
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

1. Read the blocked URL from the console and add only that origin to `script-src`.
2. For inline scripts, generate a per-request nonce and put it on the tag and in the header.
3. Roll out changes with `Content-Security-Policy-Report-Only` first, then enforce.

```http
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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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.

## Sources

- [MDN: CSP script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src)
- [MDN: Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP)

## Related

- [Fix: missing security headers](/fix/missing-security-headers)
- [Security headers checker](/tools/security-headers-checker)
- [Fix CSP warning: 'unsafe-inline' allows unsafe scripts](/errors/csp-unsafe-inline-warning)
- [All errors](/errors)
