Rolling out a CSP with Report-Only and violation reports
In one line: How Content-Security-Policy-Report-Only behaves, report-uri versus report-to, designing a collector, and the switch to enforcing.
Deploying a CSP straight into enforcing mode breaks parts of the site silently. In practice you ship Content-Security-Policy-Report-Only first, collect violations, refine the policy, then enforce.
1. What Report-Only does
- The browser evaluates the policy but does not block.
- Violations are reported and logged as console warnings.
- It can sit alongside the enforcing header, previewing the next policy.
2. report-uri versus report-to
| Directive | Format | Status |
|---|---|---|
report-uri /csp-report | One POST per violation | Widely supported, deprecated in CSP3 |
report-to csp-endpoint | A Reporting API group name | Preferred, browser support varies |
report-to needs the group defined in a separate header.
Report-To: {"group":"csp-endpoint","max_age":86400,
"endpoints":[{"url":"https://reports.example.com/csp"}]}
Content-Security-Policy-Report-Only: default-src 'self'; report-to csp-endpoint
Shipping both is common for compatibility. CspLab only reports "no violation reporting" when neither is present.
3. What a report contains
{
"csp-report": {
"document-uri": "https://app.example.com/checkout",
"violated-directive": "script-src-elem",
"effective-directive": "script-src-elem",
"blocked-uri": "https://cdn.example.net/lib.js",
"source-file": "https://app.example.com/checkout",
"line-number": 128, "column-number": 24
}
}
Cookies and tokens are not included directly, but URLs can carry query parameters. Decide retention and access before you collect.
4. The switch
- Collect in Report-Only for one to two weeks, grouped by
blocked-uriandeffective-directive. - Add only the origins you truly need, and fix code that still depends on
'unsafe-inline'. - When reports approach zero, enforce — starting with the highest-risk directives such as
script-src,object-srcandbase-uri. - Keep Report-Only running for a while to watch for regressions.
5. Common mistakes
- Reports going nowhere — using a
report-togroup name without the Report-To header collects nothing. - Treating Report-Only as final — it never blocks; the enforcing header is separate.
- Report floods — a policy with many violations can overwhelm the collector. Prepare sampling or aggregation.
Paste the same policy into the tool to see the score and the directives to change.
Open CspLabFrequently asked questions
Does Report-Only stop XSS?
No. It only reports. Actual protection comes from the enforcing header.
Can I use both `report-to` and `report-uri`?
Yes. Browsers report to whichever they support. To avoid duplicates, group by document URI and directive on the collector.
Do reports contain personal data?
Not cookies or passwords directly, but `document-uri` may contain query parameters. Normalise URLs and set retention before collecting.
Sources
Keep reading
- CSP directive structure and default-src inheritanceHow a policy string splits into directives and sources, which directives inherit default-src, and what an empty value actually does.
- nonce, hash and strict-dynamic: allowing inline scripts safelyHow nonce and hash let you drop unsafe-inline without breaking inline scripts, how strict-dynamic disables the host allowlist, and the correct combinations.
- Nine CSP bypass patterns and the attacks they enableunsafe-inline, wildcards, data:, blob:, http:, missing base-uri, sandbox escapes and nonce-less strict-dynamic: the combinations that defeat a policy.