The report-to Directive
You'll learn how to use the modern report-to directive to send CSP violations to a structured reporting endpoint.
What Is the report-to Directive?
The report-to directive is the next-generation replacement for the older report-uri directive you just learned. Instead of sending violation reports to a simple URL, report-to integrates with the browser's Reporting API, which provides a standardized, structured way to collect all kinds of browser reports—not just CSP violations, but also deprecation warnings, network errors, and more.
Think of it like upgrading from sending handwritten notes to using a modern messaging system with read receipts, retry logic, and organized inbox folders.
How It Works
The report-to directive references a named reporting group that you define separately in a Report-To HTTP header. This group specifies where reports should be sent, how often, and other configuration details:
Report-To: {"group":"csp-endpoint","max_age":10886400,"endpoints":[{"url":"https://example.com/csp-reports"}]}
Content-Security-Policy: default-src 'self'; report-to csp-endpoint
Here, violations will be sent to the csp-endpoint group, which routes them to your specified URL. The browser batches and sends reports automatically—you don't need to do anything extra in your JavaScript.
Why Use report-to Over report-uri?
The Reporting API is more robust and efficient. It batches reports, handles retries automatically, and uses a consistent JSON format across all report types. Many modern services that handle CSP monitoring expect this format.
Key Takeaway: Use report-to with the Reporting API for modern, structured CSP violation reporting that's more reliable and integrates with broader browser monitoring capabilities.