Skip to content

Lesson 7 of 9 · 23m

Rolling Out CSP Without a Production Bonfire

The report-only-to-enforcing pipeline, environment-specific rollout, backwards-compatible CSP syntax, and how to stage exceptions responsibly.

The correct first deployment of CSP blocks nothing. Teams that skip report-only mode learn about every browser extension, translation service, legacy widget, and forgotten admin page simultaneously — during the incident review. Rollout is an operational process, not a header paste.

Start with report-only

Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-abc' 'strict-dynamic'; object-src 'none'; base-uri 'none'; report-uri /csp-report

The browser evaluates violations and reports them, but allows the behavior. This exposes the difference between your intended application and the real one. Run it long enough to catch weekly jobs and rarely used flows — a few hours on the marketing home page tells you almost nothing.

Do not interpret zero reports as success. Ask whether reporting works, whether traffic exercised authenticated pages, and whether mobile clients send reports differently.

Ship enforcement behind control

Use a config switch so rollback does not require a deploy:

if settings.csp_mode == "off":
    return response
header = "Content-Security-Policy" if settings.csp_mode == "enforce" else "Content-Security-Policy-Report-Only"
response.headers[header] = build_policy(nonce=request.csp_nonce)

Roll forward by population: internal users, one low-risk route, then broad traffic. For large applications, route-specific policies are legitimate. An admin console may need blob: workers while the public site does not.

Compatibility is intentional, not accidental

Older browsers do not understand every directive. Newer browsers ignore 'unsafe-inline' when a nonce or hash is present in script-src; older ones may still need it. This lets you write one policy that is strict where possible and functional where not:

script-src 'self' 'nonce-abc' 'strict-dynamic' 'unsafe-inline' https:

That looks alarming until you understand the negotiation: modern browsers ignore the weak parts because nonce/strict-dynamic are present; legacy browsers use the host/inline fallback. Do not copy this pattern without deciding that legacy support is worth the residual risk.

Exceptions need ownership and expiry

A temporary exception should be data, not folklore:

{
  "directive": "img-src",
  "source": "https://legacy-cdn.example",
  "owner": "growth",
  "expires": "2026-03-01",
  "reason": "legacy email asset host; migration in progress"
}

Without an owner and expiry, temporary means permanent. Prefer nonce/hash mechanisms or proxying over adding broad HTTPS wildcards.

Field notes

  • Multiple policies are combined intersection-style. Your CDN, framework, and application may all add one; enforce in exactly one place.
  • Report-only volume can be enormous. Sample after initial triage, but do not sample during the first inventory.
  • Browser extensions cause reports you cannot fix. Learn their fingerprints and filter them downstream rather than weakening the policy.
  • Keep a one-click way to return to report-only. CSP rollback is rare but fast rollback is cheap insurance.

Was this lesson helpful?

Sign in to rate