The Content-Security-Policy-Report-Only HTTP header is a powerful tool for testing and monitoring the effects of a Content Security Policy (CSP) without enforcing it.
It allows you to define a CSP and receive violation reports in the browser's developer console or a specified reporting endpoint, without blocking any content.
This is particularly useful for testing CSP rules in a production environment without risking breaking your website
For example:
default-src 'self'
: Allow resources only from the same origin.
script-src 'self' https://trusted.cdn.com
: Allow scripts only from the same origin and a trusted CDN.
report-uri /csp-violation-report-endpoint
: Specify the endpoint (mandatory) where violation reports will be sent.