opyebCspLab

Rolling out a CSP with Report-Only and violation reports

Operations · 6 min

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

DirectiveFormatStatus
report-uri /csp-reportOne POST per violationWidely supported, deprecated in CSP3
report-to csp-endpointA Reporting API group namePreferred, 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

  1. Collect in Report-Only for one to two weeks, grouped by blocked-uri and effective-directive.
  2. Add only the origins you truly need, and fix code that still depends on 'unsafe-inline'.
  3. When reports approach zero, enforce — starting with the highest-risk directives such as script-src, object-src and base-uri.
  4. Keep Report-Only running for a while to watch for regressions.

5. Common mistakes

  • Reports going nowhere — using a report-to group 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 CspLab

Frequently 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

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)