Another suitable mitigation strategy may be lock dependencies version or switch to other programming languages with a proper standard library and limited number of packages where one can at least audit the code.
But you’re probably looking for something more general, like containers, virtual machines, or other sandboxes (chroot?).
yarn install --flat
git add node_modules
Then the next time you run yarn upgrade: yarn upgrade --flat
git diff
Carefully read through what changed in each of the packages. git add node_packages
git commit -m "yarn upgrade"
You will see a lot of bad code, but also learn stuff. But most importantly - your project will be secure.Keep backups on an external file store just in case.
Use a filesystem that has snapshot capabilities.
Snapshots on an external system is useful but few are disciplined enough to take regular enough snapshots.
I'd argue the root/normal user separation is largely useless on single user desktop computers.
You want a world where a browser exploit can drop a bootkit? Nahhh
Don't download, install and run random code libraries from the internet, assume they are hostile until proven otherwise.
As horrible and impracticable as it sounds, the only way to prevent this happening is to read the source of every (/transitive) dependency you install. Yes, we can trust people, and yes, we can blame them when they betray our trust - we can even prosecute them - but as this shows, that's not always going to stop people. And it's certainly not going to stop attackers who gain control of those dependencies.
This is something we really need to think about as a profession. I would favour a system where dependencies are restricted to pure computation only (no syscalls) and any greater permissions must be granted explicitly. But that's extremely onerous, and likely - for many devs - to lead to a 'just click yes' mentality; even besides that, there are doubtless many cases it won't prevent. All I'm sure of is that we can't continue like this.