The report-uri Directive
What you'll learn: How to configure a specific endpoint where browsers will send CSP violation reports for monitoring and analysis.
What Is report-uri?
The report-uri directive tells the browser where to send JSON-formatted violation reports when your Content Security Policy is violated (or when testing in report-only mode). Think of it as a mailbox where the browser drops detailed incident reports every time something breaks your CSP rules.
Without report-uri, violations happen silently in production—you'd never know that your CSP is blocking legitimate resources or being triggered by actual attacks. With it, you get real-world feedback on what's being blocked and why.
How It Works
When a CSP violation occurs, the browser automatically sends a POST request containing violation details to the URI you specify:
Content-Security-Policy: default-src 'self'; report-uri https://example.com/csp-reports
The browser sends JSON reports like this to your endpoint:
{
"csp-report": {
"document-uri": "https://example.com/page",
"violated-directive": "script-src",
"blocked-uri": "https://evil.com/malicious.js",
"original-policy": "default-src 'self'; report-uri ..."
}
}
Setting Up Your Endpoint
Your reporting endpoint needs to:
- Accept POST requests with
application/csp-reportcontent type - Log or store the violation data for analysis
- Respond quickly (browsers may limit retry attempts)
- Handle potentially high traffic during attacks
Many developers use third-party services like report-uri.com or build simple logging endpoints to collect this data.
Key Takeaway: The report-uri directive specifies where browsers should send CSP violation reports, enabling you to monitor policy effectiveness and detect both configuration issues and actual security threats in production.