Multiple CSP Headers and Policies
What you'll learn: How browsers merge multiple CSP headers and when you'd intentionally use multiple policies.
When a browser receives multiple Content-Security-Policy headers from the server, it doesn't pick one and ignore the rest—it combines them all, applying the strictest restrictions from each.
How Browsers Merge Multiple CSP Headers
Think of multiple CSP headers like stacking security filters. Each header adds its own restrictions, and the browser enforces all of them simultaneously. If one header allows script-src 'self' and another allows script-src cdn.example.com, the browser will only allow scripts that satisfy both policies—which in this case means nothing can load (no overlap).
The intersection logic means:
- More headers = more restrictions
- Scripts/resources must pass every policy to load
- The most restrictive combination always wins
When to Use Multiple Policies
Intentional use cases:
- Gradual tightening: Add a stricter policy while keeping the old one during migration
- Defense in depth: Layer policies from different configuration sources (application + infrastructure)
- Combining with report-only: Use
Content-Security-Policy(enforcing) alongsideContent-Security-Policy-Report-Only(monitoring)
Common mistake:
Accidentally setting multiple enforcing headers that conflict completely, blocking all resources. This typically happens when:
- Multiple middleware layers each add CSP headers
- Server config and application both set headers
- Reverse proxy adds headers on top of app headers
Debugging Multiple Headers
Check your browser's DevTools Network tab to see all CSP headers sent. If resources aren't loading, you may have conflicting policies that create an impossible-to-satisfy intersection.
Key Takeaway: Browsers enforce all CSP headers simultaneously by applying the strictest rules from each—be intentional about multiple policies or you'll accidentally create overly restrictive (or broken) security rules.