Remix.run Logo
▲ duxup a day ago

Let’s say I use Optimizely (I don’t), is there a good best practice to say?:

“yeah load this JS m, but it can’t load / random other JS referencing sketchy places”

▲Jach a day ago | parent | next [-]

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.

▲horsawlarway a day ago | parent [-]

Yeah, honestly I wish they'd move that section higher up - it's probably he most genuinely useful tidbit in the article.

As an aside - I'm rabidly against "analytics" companies that come in and suggest that the right "getting started" choice is to drop untrusted JS they own (and can update at any time) onto your site.

It's "easy", but it completely breaks your security model.

If I were a lawyer... I'd be taking a serious look at putting optimizely into the meat grinder for recommending 'unsafe-eval' as a script source... it literally has "unsafe" in the fucking name for a reason. This alone should end the company. It won't, because this space is absolutely FILLED with scummy behavior, but it should.

---

A strict CSP is one of the most meaningful ways you have right now as a web developer to reduce attack surface. People should take advantage of it.

There's a reason browser vendors now force basically all extensions into a strict CSP by default... https://developer.chrome.com/docs/extensions/reference/manif... They won't even let you manually relax it anymore.

▲cowlevel a day ago | parent [-]

I think the kinds of people with "security models" are not the kinds of people with third-party analytics. They're marketing to people who want it to Just Work.

▲horsawlarway 13 hours ago | parent [-]

Optimizely is widely used within many large Saas companies. Including those with literal legal security requirements (soc 2, iso 27001, etc).

So are equivalent companies that recommend similar strategies. Sprig, segment, amplitude, launchdarkly, heap, full story, etc...

It's a very long list.

They all operate on the same strategy. Pitch to execs that they solve real problems and they have basically no eng cost to implement.

All you need to do is inject them into your page with absolutely no restrictions and let them run any scripts they'd like.

▲1a527dd5 a day ago | parent | prev | next [-]

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

▲cowlevel 14 hours ago | parent | next [-]

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.

▲stavros a day ago | parent | prev | next [-]

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.

▲technion a day ago | parent [-]

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,

▲skeeter2020 a day ago | parent | next [-]

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.

▲computerfriend a day ago | parent | prev [-]

It's a feature. Changes to prod should always be reviewed and this fundamental incompatibility with insecurely hosted JavaScript is a signal that it is a bad idea.

▲mook a day ago | parent [-]

Unfortunately, in this case the insecurely hosted JavaScript is the feature; that is, people who are not responsible for sites going down or breaches want to be able to add things nilly-willy (which therefore necessitates a way to bypass review).

▲skeeter2020 a day ago | parent | prev | next [-]

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

▲duxup a day ago | parent | prev [-]

Very cool thank you.

▲JoshTriplett a day ago | parent | prev | next [-]

Yes. You install a CSP that says "my site cannot load any scripts from third parties". And then any script you run, you audit thoroughly and then host on your own website, ensuring it doesn't try to load anything third-party.

Never load third-party JavaScript on your site. Zero exceptions.

▲r1ch a day ago | parent | prev [-]

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.