Skip to content

Tutorial · Security · Intermediate · 5 min read

CSP Violation Reporting in 2026: Set Up report-to Safely

Learn to deploy Content-Security-Policy-Report-Only with Reporting-Endpoints and report-to, collect CSP violations safely, and move to enforcement without breaking your site.

Updated 24 October 2026. A Content Security Policy (CSP) can limit where your website loads scripts and other resources, reducing the impact of some cross-site scripting (XSS) attacks. But turning on a strict policy without testing can break legitimate functionality. This tutorial shows how to collect CSP violation reports first, triage them and move carefully towards enforcement.

1. Understand the three moving parts

  • Content-Security-Policy-Report-Only defines a proposed policy and records violations without blocking those resources.
  • Reporting-Endpoints maps a short name, such as csp, to a secure HTTPS report collector.
  • The report-to directive tells supporting browsers which named endpoint should receive CSP violation reports; report-uri remains a useful legacy fallback.

The older Report-To HTTP header is deprecated; use Reporting-Endpoints for new deployments. Reporting is an observability mechanism, not a replacement for an enforced CSP, input validation, contextual output encoding or framework security fixes.

2. Start with a report-only policy

Serve these HTTP response headers on HTML pages from your web server, CDN or edge platform. Replace example.com with your own HTTPS origin and implement the report collector before enabling reporting. This deliberately conservative policy is a starting point for testing, not a universal production allowlist.

Example
Reporting-Endpoints: csp="https://example.com/_csp"
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; report-uri https://example.com/_csp; report-to csp

3. Configure a safe reporting endpoint

  1. Create a dedicated HTTPS POST endpoint for CSP reports; make sure it is not protected by a login or CSRF token that prevents browser delivery.
  2. Accept the modern application/reports+json payload (often a JSON array) and, for legacy report-uri, application/csp-report (typically an object with a csp-report field).
  3. Validate content types and structure, limit request body size and request rate, and return a simple 204 response. Do not execute or render any reported strings as HTML.
  4. Strip or minimise potentially sensitive URL paths, query strings, referrers and script samples before storage. Set retention and access controls appropriate to your privacy obligations.
  5. Exclude the collector from policies or infrastructure rules that accidentally prevent reports, and monitor collector failures without making page availability depend on reporting.

CSP reports are untrusted telemetry: they can be forged, duplicated, delayed or missing. A lack of reports does not prove your policy is safe or your website has no XSS.

4. Verify the response headers and generate a test violation

Example
curl -sS -D - -o /dev/null https://example.com/
# Confirm both Reporting-Endpoints and
# Content-Security-Policy-Report-Only appear on the HTML response.
  1. Open a staging page in a current browser with DevTools Network and Console visible.
  2. On a page you control, attempt to load a harmless test script from a disallowed origin. With report-only, it may still load; inspect the console's CSP report-only warning.
  3. Check the collector for a matching report. Repeat with a browser that uses the legacy report-uri fallback if that support matters to your audience.
  4. Test routes, authentication flows, payment and analytics integrations, and third-party widgets. Some reports may be noise from extensions or injected software.

5. Triage reports instead of weakening the policy

  • Group by effective directive, blocked origin and affected page, then investigate the most frequent and user-impacting violations.
  • Confirm whether each blocked resource is genuinely required; remove unused third-party scripts instead of allowlisting everything.
  • Prefer nonces or hashes for necessary inline scripts and avoid broad unsafe-inline or unsafe-eval allowances.
  • Treat reports as clues rather than exploit proof. Use controlled tests and server-side evidence before labelling a report a security incident.

6. Move to enforcement gradually

Once the candidate policy works across representative browsers and important user journeys, move its vetted directives into an enforced Content-Security-Policy header. Keep reporting configured and watch for regressions. Roll out to staging and a small production slice before a site-wide change; prepare a rollback path.

Example
Reporting-Endpoints: csp="https://example.com/_csp"
Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; report-uri https://example.com/_csp; report-to csp

7. Troubleshoot missing or noisy reports

  • No reports? Confirm the endpoint URL is HTTPS, the name in report-to matches Reporting-Endpoints, the headers are on the document response, and the collector accepts both modern and legacy formats.
  • Reports but no blocking? That is expected for Content-Security-Policy-Report-Only; use Content-Security-Policy to enforce once ready.
  • Only some browsers report? Check compatibility, delivery timing, privacy settings and network blocking; the Reporting API does not guarantee delivery.
  • Too many reports? Rate-limit and aggregate safely; don't automatically add every reported origin to your allowlist.

How Zenith can help

Zenith's supported security.no-csp and security.weak-csp findings can flag an absent or weak visible CSP on an audited website. This guide explains how to test and improve such a policy before enforcement. Zenith's external audit cannot confirm that your private report collector works, that every browser sends reports or that an application is free of XSS. Validate those steps yourself.

Official standards and practical references

  • MDN — CSP report-to directive (Baseline 2026): https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/report-to
  • MDN — Reporting-Endpoints response header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints
  • MDN — Content-Security-Policy-Report-Only: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy-Report-Only
  • W3C — Content Security Policy Level 3: https://www.w3.org/TR/CSP/
  • OWASP — Content Security Policy Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html

Glossary

CSP
Content Security Policy, an HTTP security mechanism that restricts resources and some behaviours allowed on a page.
Report-only
A mode that observes potential CSP violations without blocking the relevant resource.
report-to
A CSP directive naming a Reporting API endpoint group for violation reports.
Reporting-Endpoints
An HTTP response header mapping report destination names to HTTPS URLs.
report-uri
A deprecated CSP reporting directive retained as a compatibility fallback for older browsers.
XSS
Cross-site scripting, where untrusted content causes script execution in another user's browser.