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

Code
Reporting-Endpoints: csp="https://reports.example.com/csp"
Content-Security-Policy-Report-Only: default-src 'self'; report-to csp

The 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 patternInvestigationPossible next step
First-party asset blockedCheck route, deployment path, and directiveCorrect the path or policy scope
Known third-party serviceConfirm the feature and exact required originAllow only the required origin and resource type
Inline script or styleIdentify the owner and whether it is stableMove it out, or use a nonce or hash
Unknown or extension sourceCompare browsers and reproduce with a clean profileDo 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

  1. Collect reports for representative routes and browsers while the candidate policy is report-only.
  2. Fix unintended dependencies and write down every remaining exception with an owner.
  3. Enforce the policy in a test environment and exercise authentication, forms, uploads, and embedded tools.
  4. 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.

Official references