A plain-language guide to Content Security Policy

Content Security Policy sounds intimidating, but its core idea is simple: tell the browser where scripts may come from.

Trust nothing that crosses a boundary

We review dependency updates like code, because they are code. A weekly job opens one pull request with the changelog links attached.

  • Escape late, at the point of output
  • Start CSP in report-only mode
  • Review dependency updates weekly
  • Require two-factor for deploy access

Security is a process, not a product.

Bruce Schneier

Headers that do real work

Two-factor authentication is on for every account that can deploy, and shared passwords live in a manager, not in a chat thread.

Sanitise on the way in, escape on the way out, and do both as late as possible. That one rule covers most of the bugs we find in reviews.

12 comments on “A plain-language guide to Content Security Policy”

  1. Clear and practical, thank you. One question: how long did the whole change take from start to finish?

  2. I shared this with my team. The list near the end is going straight into our onboarding doc.

    1. Elin Sørensen

      Good question. It took about three weeks, most of it waiting for review and measuring the results.

  3. This is exactly the write-up I needed this week. We hit the same problem and ended up with a much messier fix.

    1. Elin Sørensen

      Good question. It took about three weeks, most of it waiting for review and measuring the results.

  4. Kwame Asante

    This is exactly the write-up I needed this week. We hit the same problem and ended up with a much messier fix.

  5. Nadia Petrova

    Nice to read something that admits the first attempt did not work. That is how it goes in real projects.

  6. Bookmarked. The part about writing things down before changing anything is underrated.

    1. Elin Sørensen

      Glad it helped. A follow-up is on the list, so keep an eye on the blog.

  7. Great post. Did you measure this on a real phone as well, or only with throttling in the browser?

Leave a comment

Your email address will not be published. Required fields are marked *