Course contentsShow
← Web Development
Lesson 2870 of 2,98251. Content Security PolicyFree lesson

Analyzing CSP Violation Reports

Understand the structure of violation reports and how to identify problematic resources.

Analyzing CSP Violation Reports

You'll learn how to decode CSP violation reports so you can quickly identify which resources are breaking your policy and fix them.

What Are Violation Reports?

When you've set up report-uri or report-to directives, browsers send JSON reports whenever something violates your Content Security Policy. Think of these reports as security incident logs—each one tells you exactly what happened when a resource tried to load but was blocked (or would have been blocked in report-only mode).

Report Structure

A typical CSP violation report contains several key fields:

  • document-uri: The page where the violation occurred
  • violated-directive: Which CSP rule was broken (e.g., script-src)
  • blocked-uri: The resource that tried to load
  • source-file: Where the violating code originated
  • line-number and column-number: Exact location in the source file
  • disposition: Whether it was "enforce" or "report" mode

Reading the Tea Leaves

When analyzing reports, focus on patterns:

{
  "violated-directive": "script-src 'self'",
  "blocked-uri": "https://evil-ads.example.com/inject.js",
  "document-uri": "https://yoursite.com/checkout"
}

This tells you: an external script from evil-ads.example.com tried to run on your checkout page but was blocked because your policy only allows scripts from 'self'.

Common Scenarios

  • Browser extensions: Look for chrome-extension:// or moz-extension:// URIs—often false positives
  • Inline scripts without nonces: Shows inline as the blocked resource
  • Third-party widgets: CDN URLs you may have forgotten to whitelist

Key Takeaway: CSP violation reports are structured JSON logs that pinpoint the exact directive, resource, and location of policy violations—analyze the violated-directive and blocked-uri fields first to identify problematic resources quickly.