Deploy a Content Security Policy safely
8 steps · about 4 h 15 min · Intermediate
- Model the policy (guide, OWASP, 40 min)
Understand how directives restrict resource types and how fallback directives interact.
- Prefer a strict policy (guide, web.dev, 40 min)
Base script trust on nonces or hashes instead of maintaining fragile host allowlists.
- Observe before enforcing (reference, MDN, 30 min)
Collect violations from real routes while the candidate policy is not yet blocking resources.
- Constrain script execution (reference, MDN, 35 min)
Remove broad script permissions and account for modules, workers and dynamically loaded code.
- Issue per-response nonces (reference, MDN, 30 min)
Authorise intended inline blocks without turning a reusable value into a bypass.
- Control who may frame the site (reference, MDN, 25 min)
Reduce clickjacking exposure independently of script and resource rules.
- Remove mixed-content paths (reference, MDN, 25 min)
Upgrade legacy subresource URLs while verifying that every dependency is actually available over HTTPS.
- Triage violation reports (guide, MDN, 30 min)
Separate real breakage and attacks from extensions, stale pages and harmless browser noise before enforcement.