← Back to context

Comment by 1a527dd5

11 days ago

Yes: https://developer.mozilla.org/en-US/docs/Web/Security/Defens...

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.

  • 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,

    • I remember a team at my old place bringing down the entire app with insufficient defense around an Optimizely script that failed. Seems bonkers to take on these dependencies and I think it's only going to get worse.

There's no reason to use SRI any more since caches became partitioned. It won't share the cache between different websites for privacy reasons so you may as well just host the file yourself, and then there's not much reason to use SRI.

this will prevent an unexpected version but doesn't stop a legit but compromised include from loading nefarious resources