Course contentsShow
← Web Development
Lesson 2871 of 2,98251. Content Security PolicyFree lesson

Running Enforcing and Report-Only Policies Simultaneously

Deploy both headers together to enforce one policy while testing a stricter one.

Running Enforcing and Report-Only Policies Simultaneously

What you'll learn: How to deploy both Content-Security-Policy and Content-Security-Policy-Report-Only headers at the same time to enforce one policy while testing a stricter one without breaking your site.

The Core Idea

Your browser can process two CSP headers simultaneously: one that enforces rules and blocks violations, and another that runs in report-only mode to monitor what would break if enforced. This lets you maintain a stable, working policy while testing a more restrictive policy before deploying it.

Think of it like having training wheels (your enforcing policy) while practicing tricks with no training wheels (your report-only policy). If you fall during practice, nothing bad happens—you just get data about what needs fixing.

Why This Matters

When tightening your CSP—say, removing 'unsafe-inline' or adding 'strict-dynamic'—you risk breaking functionality. By running both policies together, you can:

  • Keep your site working with the current enforcing policy
  • Collect real-world violation reports from the stricter report-only policy
  • Identify all issues before making the stricter policy live
  • Gradually roll out security improvements with confidence

How It Works in Practice

Your server sends both headers:

Content-Security-Policy: script-src 'self' 'unsafe-inline'; report-uri /csp-report
Content-Security-Policy-Report-Only: script-src 'self' 'nonce-xyz123'; report-uri /csp-test-report

The first policy allows inline scripts (enforced). The second requires nonces (report-only). Inline scripts run normally, but violations of the stricter policy get reported to /csp-test-report.

Once reports show no violations for several days, you can safely promote the report-only policy to enforcement.

Key Takeaway: Deploying enforcing and report-only CSP headers together lets you safely test stricter security policies in production without risking downtime or broken functionality.