6 ms·
NPM Package Hijacking From the Hijacker's Perspective
- jwcrux 11y agoI'm not a JS dev, but would it be possible for a malicious actor to create a pre/post install script that looks for packages published by the current user and "worms" its way into those pre/post install scripts? If this were possible, something like this could have the potential to infect quite a few npm modules.
- istoica 11y agoyes, it basically means this and it is not about npm in itself, it can also be gem, a pod, a jar ... basically what he highlights is that there is a lot of trust in these days in the open source repositories towards non-certified/verified contributors. There are others that already found the secure ways, such as the Linux kernel developers. I as a non developer, compared to them, in the web world, I put a lot of trust in the other, with almost no idea what/who he is, mostly a basic read of his username/github profile. And npm architecture, the "ultimate" code reuse repository, due to "there's an npm for sum(a,b)" that they so madly promote, it is extremely sensitive to exactly these types of maliciousness. Maybe npm will start to introduce policies, boards, advisers, commissions, really start to act professionally as it should, maybe this will work, but up to a point, in the end, it is the dev's problem to use the proper shit, and have some basic "wash your hands before you eat" type of rules: - use as little dependencies as possible, it will byte you later, it has been proven, don't head this road, fuck it! - ensure a back-up for that stuff, use a FTP account if you still are in that era, put them on S3 or even Dropbox, it is modern times, you have the means. - when you finally decide on one, check a little bit its usage rate, its latest commit date, its main, contributors, its image, yes, be shallow, look at the clothes, it must look good to the eye too. Ensure at least the dev tried its best in his available time there, get involved, read the number of users, the magic stars, the votes, the ratings, the songs, the novels, the books. Have a problem, not in the github issues, a functionality change, well, don't just beg for it opening a new bloody issue, fork the stuff, fork it hard and add your new magic trick and then create PR for yourself to shin and let others handle it from where you left. Be wise, improve yourself, be polite, be nice, look at the dependency's dependencies too, if they are shady, fuck it! roll your own! - most of the programmers these days, especially web ones, tend to rush to solution with their new agile/kanban/shalmban methodologies, their golden paths to success and ideologies, without taking time to do some housekeeping, I also do not blame, sometimes it really is without actually HAVING any time at all because the Scrum Master 5000 expect deliveries, solutions, not problems - I am a human, I live, I eat, I sleep - I do not have time for your shit, if you want it fast like that and don't accept my own timeline after presenting it to you 100 times in every daily stand-up shit, then fuck-it - no housekeeping, I go shady I start a dance with the wolves! - there is something rotten in Denmark with this "there's a start-up for every shit" mentality from which everything flows Enjoy life!
- ENTP 11y agoThe post install script can be like any other script the user can run. There's no sandboxing so it can access anything the running user can access. So essentially, yes, it could infect any other module in there. I believe it could even run an "npm publish", which is pretty scary.
- gry 11y agoEven worse, `scp` the `~/.ssh/id_rsa` private key and known hosts file. The attack vector went tenfold.
- dineshp2 11y agoThe recent NPM situation was a real eye opener for me. I never gave much thought to the attack vectors involoving package managers. > The post install script can be like any other script the user can run. There's no sandboxing so it can access anything the running user can access. Wow. This just seems wrong that the script has such far reaching privileges.
- nmjohn 11y agoConsidering node.js is able to spawn subshells and execute whatever code it wants when running, install scripts pose no additional threat to just running the javascript.
- rdancer 11y agoThe changes a package install makes ought to be limited to the source files within its subdirectory (and perhaps some precompiled binaries). I don't quite expect it to be installing rootkits, and the principle of least privilege dictates that it should not be allowed to. Once the package is installed, it is already too late for a code review, or any mitigation. A well-written worm will never be detected. It is unexpectedly bad design (or, in case of the JavaScript community, an expectedly bad design).
- deleted 11y ago[deleted]
- jtuchsen 11y agoI've not tried this, but a similar but easier exploit would be to register packages with names that are close to existing popular package names, and then have a post install script inject a modified version of the actual package into the node_modules directory that also does something malicious. So you register the "lodasj" package instead of "lodash" and than create a post install script to inject the malicious "lodash" package that re-exports all of the lodash API + does something nasty. If someone has a typo with "npm i lodasj" and doesn't notice the mistake, the machine that installs it and anyone that depends on the package is infected. I wonder how well policed NPM is against these kinds of malware attacks.
- troygoode 11y agothey'd notice as soon as they tried to run their program as "import * from 'lodash'" would fail (unless they were consistent with their typos...)
- tyingq 11y agoThis one isn't doing anything scary at the moment, but shows the potential: https://www.npmjs.com/package/uglifyjs https://www.npmjs.com/package/uglifyjs It's getting 30k+ downloads a month. The actual package people are looking for is here: https://www.npmjs.com/package/uglify-js https://www.npmjs.com/package/uglify-js
- dclowd9901 11y agoScripts of dependencies don't run. Period. You'd have to fork someone else's repo and run npm install on that fork. If you're doing that, you ostensibly trust their code enough to inspect and work on it. If not, wtf are you doing? If you run `npm install` on a project, you're simply installing its dependencies (and actually running any pre-publish hooks too, for some stupid reason).
- deleted 11y ago[deleted]
- JdeBP 11y agoThis idea appears to be the subject of https://news.ycombinator.com/item?id=11364347 https://news.ycombinator.com/item?id=11364347 .
- DCoder 11y agoSee also: https://github.com/joaojeronimo/rimrafall https://github.com/joaojeronimo/rimrafall
- api 11y agoSecurity in a complex interdependent software ecosystem is untenable. Period. NodeJS/npm is in no way unique here. Apt, yum, gem, Homebrew, Docker hub, etc. are just as bad if not worse, not to mention "git clone" followed by "./configure" or "make." Any time you bring down code onto your machine and execute it you are... well... bringing down code onto your machine and executing it. I've been increasingly thinking that this could be a very fertile area for AI research. Security is really an AI hard problem. There is no combination of sandboxing, permissions, auditing, formulaic static code analysis, firewall hacks, etc. that will yield a system that is both (a) usable/convenient and (b) secure. Take 'npm' for instance. It's amazingly convenient but it (and all other packagers like it) is a security nightmare. Operating securely would require one to set up a shadow mirror of the entire NodeJS ecosystem and then have someone ($$$$$) manually audit every single thing in there that you are going to use and every single change that comes down from above. That's not tenable for anyone but the most lavishly funded organizations, and anything like that is universally reviled by developers since it slows them down. I've worked in environments like that before (government), and we had people quit because it was just "impossible to do my work."
- abecedarius 11y ago> There is no combination of sandboxing, permissions, auditing, formulaic static code analysis, firewall hacks, etc. that will yield a system that is both (a) usable/convenient and (b) secure. https://en.wikipedia.org/wiki/Object-capability_model https://en.wikipedia.org/wiki/Object-capability_model contradicts this, or anyway offers an alternative to the pile of hacks. It's true that none of the systems listed there are familiar; it's very hard to supplant the basic assumptions we've built on and built on since the 1970s.
- api 11y agoSeems like a complexity explosion. Un-forgeable references can be created using crypto. In a way things like Bitcoin addresses or cryptographically authenticated network endpoint addresses might qualify.
- 11y ago
- 2sk21 11y agoThis is exactly what has made me extremely nervous about NPM. There is no security oversight at all and modules running on my dev machine with my full credentials could be uploading anything - Looks like I'll have to move node.js development to a sterile VM.
- JdeBP 11y agoDuplicates https://news.ycombinator.com/item?id=11360242 https://news.ycombinator.com/item?id=11360242 .
- supermatt 11y agoWhy are modules allowed to be unpublished?
- rst 11y agoA few reasons why a module might be unpublished: 1) Legal -- copyright violation in the code itself, patent infringement, full text of a novel somehow found its way into the docs, etc. 2) Bugs or security holes, particularly if a bug is being actively exploited in the wild. Hopefully, neither of these comes up often, but when they do, you need for the mechanism to be available.
- sschueller 11y agoWhy can't we have a packages.lock like composer has? At least we can then decide if we want to install updates and keep all environments in sync.
- paulddraper 11y agonpm shrinkwrap
- tedmiston 11y ago> Caveats > If you wish to lock down the specific bytes included in a package, for example to have 100% confidence in being able to reproduce a deployment or build, then you ought to check your dependencies into source control, or pursue some other mechanism that can verify contents rather than versions. https://docs.npmjs.com/cli/shrinkwrap https://docs.npmjs.com/cli/shrinkwrap
- tedmiston 11y agoIn the Python world, you can self-host a copy of PyPI [1] (our package repo). Though you might do it for a faster build process, this can also prevent the "disappearing public repo" problem [2]. Is there something analogous for npm? 1: https://pypi.python.org/pypi/pypiserver https://pypi.python.org/pypi/pypiserver 2: http://schinckel.net/2013/04/15/my-own-private-pypi/ http://schinckel.net/2013/04/15/my-own-private-pypi/
- amk_ 11y agoOne thing that bothers me about the Node community is how the first person to implement a protocol/API/wrapper tends to name their package something like 'protocol' or 'protocol-js' instead of something like 'a-clever-differentiable-brand-name' as is common in other software communities. That makes it hard to distinguish an unmaintained package with tons of bugs from a more polished version sponsored by a big-name contributor, and makes it easy - even encourages - consumers to place unwarranted trust in packages with legitimate-sounding names. As an example, consider if a new browser on Linux was packaged as 'browser-linux' in the system repositories-- how many downloads would it get?