Skip to content

Lesson 8 of 9 · 21m

Reporting Endpoints: Collecting Signal Without Drowning in Noise

report-uri versus Reporting-Endpoints, report shapes, ingestion security, deduplication, and what violation data actually tells you.

CSP reporting is the difference between operating a control and admiring one. It is also a firehose pointed at your infrastructure by every browser, crawler, privacy tool, extension, and broken proxy on the internet. Build the pipeline for hostile, malformed, high-volume input.

Two generations of reporting configuration

The legacy form is a CSP directive:

Content-Security-Policy-Report-Only: default-src 'self'; report-uri /csp-report

The newer Reporting API separates endpoint definition from policy:

Reporting-Endpoints: csp="/csp-report"
Content-Security-Policy: default-src 'self'; report-to csp

report-uri is deprecated but still widely used as a compatibility fallback. Report-To was the older endpoint-group header; Reporting-Endpoints is the current replacement. Real deployments often carry overlapping forms during transition. Pick one canonical ingestion URL and normalize upstream.

What a report looks like

A classic report-uri payload resembles:

{
  "csp-report": {
    "document-uri": "https://app.example/settings",
    "violated-directive": "script-src-elem",
    "effective-directive": "script-src",
    "blocked-uri": "https://widgets.vendor.example/inject.js",
    "disposition": "enforce",
    "status-code": 200
  }
}

The important fields are effective-directive, blocked-uri, source-file, line-number, disposition, and sample data when present. Reports are hints, not proof. They do not contain enough context to prove exploitation, and attackers can sometimes trigger fake reports.

The endpoint is untrusted input ingestion

@app.post("/csp-report")
async def csp_report(request):
    if request.headers.get("content-type", "").split(";")[0] not in {
        "application/csp-report", "application/reports+json", "application/json"
    }:
        return Response(status_code=415)
    body = await request.body()
    if len(body) > 16_384:
        return Response(status_code=413)
    enqueue_report(body[:16_384], request.client.host)
    return Response(status_code=204)

Do not parse and query arbitrary nested attacker JSON synchronously in the request path. Queue it, cap size, rate-limit per source, and never echo report contents into HTML. This endpoint is unauthenticated by design — treat it like a public write-only sensor.

Turn noise into inventory

Normalize and group by effective directive, blocked host, document path pattern, and disposition. Typical buckets:

  • legitimate missing dependencies you must allow or proxy;
  • extensions and client-side translation (often unusual host schemes or injected inline styles);
  • security scanning and crawler artifacts;
  • actual exploit probes, usually visible as script URLs you never shipped.

Create dashboards for report volume per release. The useful alert is usually a sudden new blocked host or a spike after deployment, not the existence of reports.

Field notes

  • Browsers omit or truncate fields differently. Build a schema-tolerant parser and preserve the raw payload for a retention window.
  • Privacy matters: document URIs can contain sensitive paths or tokens. Redact query strings and restrict dashboard access.
  • Reports sent to the same origin can themselves be affected by CSP delivery bugs; test reporting with curl-like generated payloads and browser smoke tests.
  • Reporting endpoints are useful for Report-Only network, COEP, and other browser reporting beyond CSP. Design once, reuse carefully.

Was this lesson helpful?

Sign in to rate