Deploy a Content Security Policy safely

8 steps · about 4 h 15 min · Intermediate

  1. Model the policy (guide, OWASP, 40 min)

    Understand how directives restrict resource types and how fallback directives interact.

  2. Prefer a strict policy (guide, web.dev, 40 min)

    Base script trust on nonces or hashes instead of maintaining fragile host allowlists.

  3. Observe before enforcing (reference, MDN, 30 min)

    Collect violations from real routes while the candidate policy is not yet blocking resources.

  4. Constrain script execution (reference, MDN, 35 min)

    Remove broad script permissions and account for modules, workers and dynamically loaded code.

  5. Issue per-response nonces (reference, MDN, 30 min)

    Authorise intended inline blocks without turning a reusable value into a bypass.

  6. Control who may frame the site (reference, MDN, 25 min)

    Reduce clickjacking exposure independently of script and resource rules.

  7. Remove mixed-content paths (reference, MDN, 25 min)

    Upgrade legacy subresource URLs while verifying that every dependency is actually available over HTTPS.

  8. Triage violation reports (guide, MDN, 30 min)

    Separate real breakage and attacks from extensions, stale pages and harmless browser noise before enforcement.