Setting Content-Security-Policy-Report-Only Header
You'll learn: How to configure the Content-Security-Policy-Report-Only header to safely test CSP rules before enforcing them.
What This Header Does
The Content-Security-Policy-Report-Only header works exactly like the regular Content-Security-Policy header, but with one crucial difference: it monitors violations without blocking them. Your page runs normally, but the browser reports what would have been blocked if enforcement were active.
Think of it like a speed camera in "audit mode" — it records speeding vehicles but doesn't issue tickets. You can see what violations occur in your real-world traffic before deciding to enforce strict limits.
Configuring the Header
Set it via HTTP response headers on your server:
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-abc123'; report-uri /csp-violations
Or via meta tag (less common, but possible):
<meta http-equiv="Content-Security-Policy-Report-Only"
content="default-src 'self'; script-src 'self'; report-uri /csp-violations">
Why Use Report-Only Mode
This header is invaluable when:
- You're implementing CSP on an existing site with many third-party scripts
- You want to test strict directives without breaking production
- You need data on which resources would be blocked before committing to a policy
- You're gradually tightening security without risking downtime
You can even run both headers simultaneously — one enforcing a basic policy, another testing a stricter one.
Key Takeaway: The Content-Security-Policy-Report-Only header lets you test CSP directives safely in production by reporting violations without blocking resources, giving you confidence before full enforcement.