upvote
Besides specifying scripts by hashes, you can also whitelist various domains: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP (and https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/...)

Feels nice knowing several years ago I worked on forcing CSP (including removing unsafe-eval) on some customers for a site builder product, as they have to manually whitelist domains which limits the impact of these sorts of attacks...

This writeup https://blog.report-uri.com/worlds-largest-brands-infected-w... has a section on how CSP helped (or didn't) in this attack.

reply
reply
SRI helps you make sure the script you're loading is what you initially thought, but doesn't ensure that script doesn't load other scripts, no? You need CSP for that.
reply
Specifying scripts by hashes is always a solid defense that platforms like this don't change their script after compromise - but in practice the whole point of optimizely and similar tools it that it's expected the script will change.

Common examples like analytics tools happily change their script bundles whenever they feel like it without just tagging a new version and letting you upgrade.

I wish SRI could be used more,

reply
Very cool thank you.
reply
In theory yes, in practice no since every SaaS wants to ship 5 times a day and add 15 new dependencies on other SaaS providers each release, and marketing wants to load gobs of 3rd party tracking and analytics code from their favorite SaaS of the day without having to get approval from those pesky security people. Let's not even mention ad networks.
reply