Before Enforcing CSP, Test That Your Reporting Endpoint Receives Reports

Test your CSP report endpoint with a report-only policy, a harmless local violation, and checks for delivery, parsing, redirects, and privacy.

Published
Reading time
7 min read
Before Enforcing CSP, Test That Your Reporting Endpoint Receives Reports
On this page

A Content Security Policy (CSP) reporting directive tells a browser where to send violation reports. It does not prove that the browser can reach the endpoint, that the endpoint accepts the request, or that your monitoring system can use the resulting data.

This workflow helps you test a CSP report endpoint with a harmless violation on a site you control, before changing a report-only policy into an enforced policy.

Key Takeaways

  • A configured endpoint is not a verified reporting pipeline. Check delivery, acceptance, parsing, and storage separately.
  • Use a report-only policy and a harmless local violation in an authorized test environment.
  • Test the reporting mechanism your target browsers actually use. Legacy report-uri and the Reporting API's report-to use different report formats.
  • Treat reports as potentially sensitive and untrusted input; limit, protect, and retain them accordingly.

Verification note: The examples below were not executed, and current MDN documentation, the CSP specification, and browser support information were not available for review in this run. Before production rollout, consult those sources and test the actual browser versions you support. Do not assume that every browser implements both reporting mechanisms or delivers reports immediately.

What an endpoint test needs to prove

There are several distinct stages between a policy header and a useful alert:

  1. The page receives the intended report-only policy and any necessary reporting endpoint configuration.
  2. The browser recognizes the policy and detects a violation.
  3. The browser attempts to deliver a report to the intended URL.
  4. The collector accepts the request's method and content type and returns a successful response.
  5. The collector parses the payload and makes a usable record available to your monitoring system.

A URL that opens in a browser or returns a successful response to a GET request proves little about steps 3–5. CSP reports are sent as POST requests, and the collector must handle the appropriate report format.

Advertisement

Prepare a controlled test

Use an HTTPS test site and collector you own or are explicitly authorized to test. The examples use https://app.example.test as a fictional local test origin. Configure it to resolve to your test server and use a certificate trusted by the test browser. Replace the hostname in the examples if your environment differs.

Serve a test page at /csp-test containing a local image reference. Ensure /test-image.png exists on the same origin so an unrelated missing resource does not confuse the test.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CSP reporting test</title>
</head>
<body>
  <h1>CSP reporting test</h1>
  <img src="/test-image.png" alt="Local test image">
</body>
</html>

Configure your server to attach a report-only CSP header to the HTML response. For a legacy report-uri test, use:

Content-Security-Policy-Report-Only: img-src 'none'; report-uri /csp-report

The image conflicts with img-src 'none'. Because this is a report-only policy, the test is intended to report the violation rather than block the image. The collector at /csp-report should accept the report and return a successful response without redirecting.

Check the response headers in browser developer tools after loading the page. A header on the image response or an error page does not establish that the test page received the intended policy.

Test the Reporting API separately

If you intend to use report-to, run a separate test with the following headers on the test page instead of the preceding CSP header:

Reporting-Endpoints: csp-endpoint="https://app.example.test/csp-report"
Content-Security-Policy-Report-Only: img-src 'none'; report-to csp-endpoint

Here, csp-endpoint is a group name, and Reporting-Endpoints associates it with the collector URL. Test this configuration in each browser you support; a browser that does not implement the relevant mechanism may not deliver a report through it.

If you deploy both report-uri and report-to, do not assume that a report arriving at one endpoint proves both paths work. Reporting directive precedence and browser support matter. Test the mechanisms separately first, then test your combined production configuration against current documentation and your browser matrix.

Check the collector before using the browser

A direct request can isolate collector problems from browser reporting problems. From a machine authorized to access the test collector, send a small legacy-shaped payload:

curl -i -X POST 'https://app.example.test/csp-report' \
  -H 'Content-Type: application/csp-report' \
  --data-binary '{"csp-report":{"document-uri":"https://app.example.test/csp-test","violated-directive":"img-src","blocked-uri":"https://app.example.test/test-image.png"}}'

If you also intend to accept Reporting API reports, check that path with a representative JSON array:

curl -i -X POST 'https://app.example.test/csp-report' \
  -H 'Content-Type: application/reports+json' \
  --data-binary '[{"type":"csp-violation","url":"https://app.example.test/csp-test","body":{"effectiveDirective":"img-src","blockedURL":"https://app.example.test/test-image.png"}}]'

These are synthetic requests, not browser-generated reports. Verify that the collector accepts the appropriate content type, responds successfully, and records the relevant fields. A 2xx response alone does not prove that parsing or storage succeeded. A collector that supports only one mechanism need not accept the other format.

Keep the endpoint URL direct: avoid HTTP-to-HTTPS, trailing-slash, login, and other redirects. Inspect the response if the request receives a 3xx; do not rely on redirect following to make reporting work. The test hostname and TLS setup must be valid for your environment.

Advertisement

Test browser delivery end to end

  1. Clear or identify previous test records so you can distinguish new arrivals. Record the test time and browser version without logging sensitive page data unnecessarily.
  2. Load /csp-test with one of the report-only configurations. Confirm the actual response headers and check the browser console for a CSP violation.
  3. Look for a report request in developer tools if the browser exposes it there. Reporting may be queued or batched, so allow time and inspect collector-side records as well.
  4. At the collector, confirm the request reached the intended path with POST, the expected content type, and a successful response. Check that a parsed record identifies the test page and image directive.
  5. Repeat for each reporting mechanism and browser version you plan to support. Finally, test the exact headers and endpoint URL intended for deployment.

A console warning establishes that the browser noticed a violation; it does not establish delivery. Conversely, a request in access logs does not prove your parser or downstream monitoring accepted the report. Correlate the stages rather than relying on a single signal.

If no report appears, verify the page's response headers, the endpoint group name and URL, TLS and DNS, server routing, firewall rules, collector method and content-type handling, and any redirects. Also investigate browser support and delivery timing. A missing report is not, by itself, proof of a particular failure.

Common Mistakes

  • Testing only with a status checker or GET: The endpoint may respond to GET but reject report POST requests or their media types.
  • Enforcing the policy during the experiment: An enforced policy can disrupt the page. Use report-only for this controlled diagnostic; evaluate enforcement separately.
  • Treating a synthetic curl request as a browser test: It checks the collector, not browser support, policy processing, or delivery.
  • Assuming a successful HTTP response means a usable report: Inspect the parsed record and downstream ingestion as well.
  • Testing an unauthorized site: Generate violations only on systems you own or have explicit permission to test.
  • Expecting one report per violation: Delivery, batching, and visibility can vary. Use the test to establish observed behavior for your environment, not a universal delivery guarantee.

Best Practices for a Reporting Collector

  • Accept only the methods and content types required by the mechanisms you support. Parse legacy objects and Reporting API arrays as distinct formats, and handle malformed input safely.
  • Treat report bodies as untrusted: enforce request-size and rate limits, avoid unsafe rendering or log injection, and monitor collector failures. Reports can be fabricated and should not be used as authentication evidence.
  • Reports can contain page URLs and other context that may expose sensitive information. Minimize collected fields, restrict access, redact where appropriate, and set a documented retention period. Avoid placing secrets in URLs.
  • Keep the collector available without redirecting to an interactive login. Protect operational access to stored reports separately, and apply abuse controls to the ingestion endpoint.
  • Roll out enforcement only after reviewing report-only findings, resolving intended resource violations, and checking that the reporting pipeline continues to function. Reports are diagnostic signals, not a complete inventory of every user's experience.

Conclusion

To test a CSP report endpoint, verify both sides of the pipeline: a controlled browser violation and a collector that accepts, parses, and retains a usable report. Repeat the test for your actual policy, reporting mechanisms, and supported browsers before enforcing the policy.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.