Remix.run Logo
827a an hour ago

There is no legitimate reason why postinstall scripts need to exist. The npm team needs to grow up and declare "starting with npm version whatever, npm will only run postinstall scripts for versions of packages published before ${today}".

tkel 5 minutes ago | parent | next [-]

I audited several postinstall scripts recently in popular packages. They seem to be mostly around using native binaries, downloading them, detecting if the platform is compatible, linking to it directly instead of having it bootstrapped by node, working around issues in older versions of npm, etc. Since dev toolchains (e.g. esbuild) are now being built in compiled languages and distributed as binaries via npm registry. If you are on a recent version of node/npm and a common/recent OS/platform, you should be able to disable all the postinstall scripts without legitimate issue.

raggi 42 minutes ago | parent | prev | next [-]

install scripts are a distraction, just like package signatures are a distraction. adding/removing either feature has no significant impact on the wormability of this package ecosystem. installed npm code is run, with nearly zero exceptions.

nine_k 26 minutes ago | parent | next [-]

The installed code may be run in different settings, under a different user, with different privileges. Say, it may not run in CI/CD at all, or run only with the test user's privileges.

Postinstall scripts run at install time, with installer's privileges.

piperswe 27 minutes ago | parent | prev | next [-]

A lot of it ends up bundled to run in a browser though, and doesn't end up running in Node.js

throwaway27448 27 minutes ago | parent | prev [-]

Surely every layer of defense in depth is a distraction except the one that prevents the problem.

amluto 22 minutes ago | parent | prev | next [-]

There is also not too much legitimacy to the fact that Rust packages can run unsandboxed when they build themselves.

adamnemecek 16 minutes ago | parent [-]

I feel like it's harder to hide malicious stuff in Rust build scripts.

Rohansi 44 minutes ago | parent | prev | next [-]

This doesn't really fix the issue though because package code is also executed at build time and during testing. Just maybe restricts the scope a little bit.

tkel 23 minutes ago | parent [-]

If you look at the last N npm worms, they all used postinstall scripts.

cluckindan 21 minutes ago | parent [-]

Is that even true?

tkel 17 minutes ago | parent [-]

shai-hulud and variants

https://www.stepsecurity.io/blog/mini-shai-hulud-is-back-a-s...

cluckindan 15 minutes ago | parent [-]

So N=1? 2? 3?

tkel 9 minutes ago | parent [-]

at least 3 that i can remember off the top my head in these last couple months. If you look further back you will find more.

guidedlight 27 minutes ago | parent | prev | next [-]

Security issues aside, they are a nightmare in enterprise environments where internet and OS access is heavily restricted.

nine_k 33 minutes ago | parent | prev | next [-]

...and only if you invoke it with --dangerously-run-postinstall-scripts; otherwise it will report an error if a postinstall script is found.

This is definitely going to affect any packages that need to link to native code and/or compile shims, but these are very few.

akoboldfrying 10 minutes ago | parent | prev [-]

With respect, post-install scripts are a total red herring. You're alarmed by them because they are code controlled by someone else that runs on your box, and they could do something bad -- yes, they are, and yes they could.

But so is the regular code in those packages! It won't run at install time, but something in there will run -- otherwise it wouldn't have been included in the dependencies.

Thinking that eliminating post-install scripts will have more than a momentary impact on exploitation rates is a sign of not thinking the issue through. Unfortunately the issue is much more nuanced than TFA implies -- it's not at all a case of "Let's just stop putting the wings-fall-off button next to the light switch", it's that the thing we want to prevent (other people's bad code running on our box) cannot be distinguished from the thing we want (other people's good code running on our box) without a whole lot of painstaking manual effort, and avoiding painstaking manual effort is the only reason we even consider running other people's code in the first place.