---
title: "A Content Security Policy blocks it only in production | Proofline"
description: "A widget works locally and is dead in production, and the console names a Content Security Policy directive."
url: https://proofline.sh/learn/csp-violation-evidence/
---

[Learning center](/learn/)

# A Content Security Policy blocks it only in production

A widget works locally and is dead in production, and the console names a Content Security Policy directive. A Content Security Policy (CSP) is a response header, so it usually exists only where the production server or CDN adds it. The maintainer needs the exact policy that was served, the violation message and the resource that was blocked.

Security incidents The Proofline team November 22, 2026 3 min read

## What a violation looks like

We served a page with `Content-Security-Policy: script-src 'self'` and one inline script, and loaded it in Chromium. The script did not run, and the console printed:

```
Executing inline script violates the following Content Security Policy directive 'script-src 'self''.
Either the 'unsafe-inline' keyword, a hash ('sha256-W5c8…='), or a nonce ('nonce-...') is required
to enable inline execution. The action has been blocked.
```

The message names the directive that blocked it and, for an inline script, the hash that would allow it. Other violations name the blocked URL. [MDN: Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP)

## Capture the policy that was served

The policy that matters is the one in the response the reporter's browser received, not the one in your configuration repository.

1.  In the Network panel, select the document request and copy the `Content-Security-Policy` and `Content-Security-Policy-Report-Only` response headers whole.
2.  Check the page's HTML for `<meta http-equiv="Content-Security-Policy">` too. A page can carry policies from both places, and every one of them must allow a resource.
3.  Copy the console's violation messages.
4.  If the blocked resource is a script, note what loaded it: the page's own code, a tag manager or another third-party script.

A page can also listen for violations as they happen, which captures them from users who cannot open DevTools:

```
document.addEventListener('securitypolicyviolation', e =>
  console.log(e.violatedDirective, e.blockedURI, e.sourceFile, e.lineNumber));
```

[MDN: `securitypolicyviolation` event](https://developer.mozilla.org/en-US/docs/Web/API/Element/securitypolicyviolation_event)

## Reproduce it locally

Serve the same policy in development. Add the copied header in the local server or dev proxy, or in a test with a route that adds it to the document response:

```
await page.route('https://staging.example.test/', async route => {
  const response = await route.fetch();
  await route.fulfill({ response, headers: { ...response.headers(), 'content-security-policy': copiedPolicy } });
});
```

Then the local page fails the same way, and you can test a change to the policy or the code before deploying it.

## Report-only policies

A `Content-Security-Policy-Report-Only` header reports violations without blocking anything. A team rolling out a new policy may run it in report-only mode first. A `[Report Only]` message for a resource means that policy did not block it. An enforced policy on the same page can still block the same resource, so check for an enforced violation too: only when there is none for that resource is the cause likely elsewhere. If the reports reach a collection endpoint, they are evidence from real users of what would break.

## Worked example: a chart that vanished after a CDN change

This example is fictional. After a CDN configuration change, the analytics dashboard's charts are blank in production. Staging and local development show them.

The reporter's console shows `Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script`. The production document's response header carries a policy added by the new CDN rule. The chart library compiled its formatters with `new Function()`, which `unsafe-eval` governs. Adding the copied header in a local route reproduced the blank charts. The team switched to the library's precompiled build rather than allowing `unsafe-eval` in the policy.

## Questions

### Why is the policy only in production?

Teams often add security headers at the edge, the load balancer or a production server configuration that development does not run. Serving the same headers in a staging environment catches these before release.

### Can a browser extension cause a CSP error?

Extensions can inject scripts that the page's policy blocks, and the console attributes the violation to the page. If the blocked source is an extension URL, it is not the app's bug. [Works in incognito](/learn/works-in-incognito/) separates them.

### Is the policy sensitive?

Rarely. It lists allowed origins, which are already visible to anyone who loads the page. The report-collection endpoint's URL may carry a token; remove it.

Return to [reproducing what someone else saw](/learn/replay-browser-bug-report/) for the other layers a replay needs.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### ["Script error." with no stack: get the real error from a cross-origin script](/learn/script-error-no-details/)
    
    Broken dependencies The Proofline team November 20, 2026 4 min read
    
-   ### [Reproduce a failed third-party script by blocking its URL](/learn/block-request-repro/)
    
    Broken dependencies The Proofline team November 22, 2026 3 min read
