Understand what report-only does and does not do
A Content-Security-Policy-Report-Only header lets a browser report violations of a candidate policy without blocking the resource. That makes it useful for finding dependencies before enforcement, but it does not itself prevent script execution or provide the protection of an enforced policy.
Treat reports as evidence to classify, not as instructions to add every reported host to an allowlist. A report can reflect a real application dependency, a browser extension, a stale page, or a malformed policy. Preserve the page route, directive, source, and browser context needed for diagnosis while minimizing sensitive URL data.
Start with a report endpoint and a narrow policy draft
Reporting-Endpoints: csp="https://reports.example.com/csp"
Content-Security-Policy-Report-Only: default-src 'self'; report-to cspThe endpoint and policy syntax must match the browser reporting mechanism you choose. Confirm that reports reach a protected collector, handle untrusted input safely, and have retention limits. Do not put credentials or private query parameters into a report URL.
Inventory the resources the page actually needs: scripts, styles, images, fonts, connections, frames, and workers. A single broad default-src directive can affect several resource types, so use explicit directives where the application needs different rules.
Classify reports before changing the policy
| Report pattern | Investigation | Possible next step |
|---|---|---|
| First-party asset blocked | Check route, deployment path, and directive | Correct the path or policy scope |
| Known third-party service | Confirm the feature and exact required origin | Allow only the required origin and resource type |
| Inline script or style | Identify the owner and whether it is stable | Move it out, or use a nonce or hash |
| Unknown or extension source | Compare browsers and reproduce with a clean profile | Do not add an unverified origin |
A report volume spike after a deploy may indicate a changed asset path or a policy mismatch rather than an attack. Group by directive and route, inspect representative samples, and avoid turning raw report counts into an incident without context.
Prefer nonces and hashes over broad inline allowances
When inline code is necessary, a per-response nonce or a hash can authorize specific content more narrowly than unsafe-inline. A nonce must be unpredictable and unique for the response and must be applied consistently to the policy and trusted element. Static hashes are suitable only when the exact inline bytes remain stable.
Do not add unsafe-eval, wildcard hosts, or a broad scheme merely to make the report dashboard quiet. Identify the dependency that needs the capability and decide whether it can be removed, self-hosted, or constrained.
Move from observation to enforcement deliberately
- Collect reports for representative routes and browsers while the candidate policy is report-only.
- Fix unintended dependencies and write down every remaining exception with an owner.
- Enforce the policy in a test environment and exercise authentication, forms, uploads, and embedded tools.
- Roll out to a limited production surface, watch blocked-resource and application-error signals, then expand.
Keep the enforced header separate from the report-only policy while you test new changes. A successful report-only period is not proof that enforcement is safe until the application has been exercised with the policy actually blocking disallowed resources.