Skip to content

Lesson 9 of 9 · 26m

Debugging Breakage: Console, Reports, and the Art of Not Weakening Everything

A field workflow for CSP, COEP, and header breakage: reproduce precisely, identify the enforcing layer, make the smallest safe exception, and verify rollback.

The worst response to a header incident is script-src * shipped in panic. The second-worst is a week of archaeology because nobody can tell whether nginx, the CDN, or the application emitted the policy. Debugging browser security controls requires the same discipline as debugging distributed systems: isolate the layer, read the actual error, change one thing.

Read what the browser actually says

Chrome DevTools will show messages shaped like:

Refused to load the script 'https://cdn.example/widget.js' because it violates
the following Content Security Policy directive: "script-src-elem 'self'".

Firefox and Safari phrase details differently, but the key facts are stable: resource URL, directive, and sometimes source file/line. Do not debug from a screenshot of the user's blank page. Reproduce in the same browser family and check whether the user has an extension injecting content.

For network-level evidence:

curl -sS -D - -o /dev/null https://app.example/settings | sed -n '/^content-security/Ip;/^cross-origin/Ip;/^strict-transport/Ip'

Then compare a path through the CDN with a path directly to the origin. Header duplication is a classic cause: CDN adds a restrictive default while the app adds its own. Browsers enforce all CSPs, effectively intersecting permissions.

Identify which layer owns the control

Browser extension -> service worker cache -> CDN edge transform -> reverse proxy -> framework middleware -> route handler

A stale service worker can preserve old HTML pointing at removed assets even when headers are current. A CDN rule can strip a header only on cached static pages. A framework middleware may only apply CSP to HTML routes while nginx applies one globally. Reproduce with cache disabled, then with a fresh profile, then from another network if needed.

Make the smallest defensible change

Bad fix:

script-src 'self' https:

Better fix:

img-src 'self' https://images.vendor.example

Best fix, when feasible: proxy the asset through your own origin, nonce the integration bootstrap, or remove the dependency. Ask what capability the fix grants. Adding an image host is not the same risk as adding a script host. Adding data: to img-src is not the same risk as adding it to script-src — and script-src data: should be treated as an emergency alarm.

Verify behavior, not just headers

A header can be present and still wrong. Write smoke checks for the flows that break most often:

python - <<'PY'
import requests
r = requests.get("https://app.example/settings", timeout=10)
print(r.status_code, r.headers.get("content-security-policy"))
assert "frame-ancestors" in r.headers.get("content-security-policy", "").lower()
PY

Then use a browser for script execution, iframe rendering, sign-in popups, payment frames, media workers, and downloads. Security-header regressions are integration regressions; static header assertions catch only half of them.

Field notes

  • <meta http-equiv="Content-Security-Policy"> cannot express reporting or frame-ancestors; use it only as a constrained fallback, never the main control.
  • Cached HTML can reference files no longer deployed. Content-hashed filenames plus immutable caching make CSP-compatible static assets much easier.
  • Violations often happen only after interaction. Console noise at page load is not the whole test.
  • During incident response, prefer switching enforce to report-only over deleting the policy wholesale. You keep visibility while restoring service.
  • Document each intentional exception near the policy builder. Six months later, nobody remembers which vendor required blob: workers.

Was this lesson helpful?

Sign in to rate