Start in report-only mode, fix what it reports, then enforce. The header Content-Security-Policy-Report-Only makes the browser report violations without blocking anything.
Steps:
- List what runs. Note your scripts, styles, fonts, frames, API hosts and third-party tools such as analytics and chat widgets.
- Write a strict policy. Use nonces or hashes with
'strict-dynamic', plusobject-src 'none'andbase-uri 'none'. Send it as report-only. - Collect reports. Point the
report-todirective at an endpoint you name in theReporting-Endpointsheader. Many teams also add the olderreport-urifor wider browser support. - Fix the violations. Move inline handlers like
onclick="..."intoaddEventListener. Add the nonce to inline scripts. Removeeval-style code. - Filter the noise. Browser extensions cause many reports that aren't your bugs.
- Enforce. Switch to
Content-Security-Policy. You can send both headers at once: the enforced policy, plus a stricter report-only one for the next step.
One limit: a <meta http-equiv> tag can hold a policy, but it can't do report-only, frame-ancestors or reporting. Use real headers for those.
Content-Security-Policy-Report-Onlyreports violations without blocking anything.- Start with a strict nonce- or hash-based policy and collect reports with
report-toorreport-uri. - Move inline event handlers into
addEventListenerand add nonces to inline scripts. - Expect noise from browser extensions.
- Enforce once the reports are clean, and keep a stricter report-only policy for the next step.
Read more
- Content-Security-Policy-Report-Only (MDN) (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only)developer.mozilla.org
- Content Security Policy Cheat Sheet (OWASP) (https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html)cheatsheetseries.owasp.org