Problem Statement: A Policy Plane for Browser Code Execution
Frames the CSP enforcer as a four-plane security platform: authoring, distribution, enforcement, and feedback.
Problem statement
Design a Content Security Policy (CSP) enforcer for a large web platform. The system must let security and product teams define, test, roll out, and operate browser-enforced policies that restrict which origins may serve scripts, styles, images, fonts, frames, and connections; generate per-response nonces so legitimate inline scripts keep working while unauthorized inline code is blocked; run in report-only mode before enforcement; and ingest, deduplicate, analyze, and act on violation reports at pageview scale.
CSP is a browser feature, not a server feature. The browser is the actual enforcement point: the server's job is to emit the correct header on every HTML response and to operate the feedback loop. That split is the heart of the design. The header is tiny and cheap; the platform around it - policy authoring, safe rollout, nonce lifecycle, violation analytics, rollback - is the engineering work.
Why the problem is distinctive
A naive answer says 'add a header that bans inline scripts.' Google's 2016 study, CSP Is Dead, Long Live CSP by Weichselbaum and colleagues, measured the deployed web and found roughly 94.7% of observed policies were ineffective against XSS because allowlists contained wildcard origins, JSONP-style endpoints, or other script-injectable sources. The lesson is architectural: an allowlist of hosts is not a security boundary by itself. Effective policies are nonce-based or hash-based, use strict-dynamic propagation, and are operated with measurement. So this question is really about building the machine that produces and maintains effective policies across hundreds of properties without breaking production.
The four planes
- Policy authoring plane: policy-as-code, compilation, validation, simulation against real page inventories, approval workflow.
- Policy distribution plane: signed immutable versions, edge and app caches, propagation SLO, instant rollback.
- Enforcement plane: per-response header emission plus nonce generation, at the edge, in app middleware, or both, chosen per route.
- Feedback plane: violation ingestion, deduplication, aggregation, dashboards, alerting, and the report-only to enforcing promotion pipeline.
A strong answer keeps these planes separate. A bad publish in the authoring plane must be stoppable before it reaches enforcement. A flood in the feedback plane must never degrade enforcement. Enforcement must keep working with the entire control plane offline, using the last known good cached policy and a local nonce source.
Public baseline versus design assumptions
Public crawl data, such as HTTP Archive's annual Web Almanac analyses, shows CSP present on only a minority of crawled responses, far behind headers like X-Content-Type-Options, which proves the operational gap this system closes. Cloudflare's published security-header analyses reach the same conclusion: adoption is low precisely because operation is hard. All scale numbers used for capacity planning in this answer are explicitly stated design assumptions for a fictional mature platform, labeled wherever they appear.
Key Highlights
- •The browser enforces; the platform authors, distributes, measures, and rolls back. Header emission is the easy 5%.
- •Host-allowlist CSP is mostly ineffective; Google's 2016 measurement found about 94.7% of deployed policies failed to block XSS.
- •Four planes: authoring, distribution, enforcement, feedback - each degrades independently.
- •Enforcement stays correct with the control plane offline via last-known-good cache and local nonce generation.
- •Every uncited scale figure in this answer is an explicit design assumption, not a company metric.
Section Rescue Kit
Buzzwords to use:
Safe statements:
- "I will separate policy authoring from header emission, because they fail differently and scale differently."
- "Before choosing where enforcement runs, let me define what must keep working when the control plane is down."