Content Security Policy (CSP) Reporting (report-uri & report-to)

Technical reference on content security policy (CSP) reporting with report-uri and report-to. Includes example strict CSP policies and JSON violation payloads.

report-uri and report-to are the feedback mechanisms for Content Security Policy. When a browser detects a violation of your policy, it sends a JSON payload to the reporting endpoint configured in your headers.

Configuring report-uri and report-to

For the broadest browser compatibility, include both report-uri and report-to in your Strict CSP, paired with the Reporting-Endpoints HTTP response header:

Reporting-Endpoints: csp-endpoint="https://demo.endpoint.csper.io/?v=1"

Modern browsers that support the Reporting API use report-to (resolving csp-endpoint from Reporting-Endpoints), while browsers that do not yet support report-to fall back to report-uri. Csper endpoints accept both formats automatically.

Example Violation Report Payload

This is an example report-uri JSON payload sent by a browser:

{
  "csp-report": {
    "document-uri": "https://csper.io/mydemovulnerablepage",
    "referrer": "",
    "violated-directive": "script-src-attr",
    "effective-directive": "script-src-attr",
    "original-policy": "script-src 'nonce-random123' 'strict-dynamic' 'report-sample'; object-src 'none'; base-uri 'none'; report-uri https://demo.endpoint.csper.io/?v=1; report-to csp-endpoint",
    "disposition": "enforce",
    "blocked-uri": "inline",
    "line-number": 1,
    "source-file": "https://csper.io/p/mydemovulnerablepage",
    "status-code": 0,
    "script-sample": "alert(1)"
  }
}

We can learn a lot of useful information from these reports:

  • The effective-directive is script-src-attr, meaning that JavaScript was included in an HTML event handler attribute (such as onerror or onclick)
  • The alert was fired from document-uri (csper.io) and was caused by source-file (sometimes these don't match up if a third-party script caused the violation)
  • We have original-policy, which is helpful for continuity or when running multiple policies
  • disposition with enforce means that the inline script was blocked (instead of only being reported on in report-only mode)
  • script-sample shows us that the blocked payload was alert(1). Uh oh! Someone was trying to perform an XSS!

There are services that collect these reports and perform aggregation, classification and analysis. Csper is one of these services.

Looking for tools to make CSP easier?

Csper has the tools to help you understand, deploy and manage your content security policy. Get started in minutes. Report aggregations, classification, analysis, alerting, realtime and more. Free 14 day trial.