233 points · by gnabgib · 1y ago · 140 comments
Does anyone have a solution to wrap binary execution (or npm execution) and require explicit user authorization for network or fs calls?
(Deno is a JavaScript runtime co-created by Ryan Dahl, who created Node.js - see his talk "10 Things I Regret About Node.js"[1] for more of his motivations in designing it.)
Then would halt due to file access or network permissions.
Could still get you if you lazily allow all everywhere though and this is why you shouldn’t do that.
deno run npm:@angular/cli --helpIf you use that, I'd highly recommend configuring it to throw an error instead of just silently skipping the postInstall though: https://github.com/karlhorky/pnpm-tricks#fail-pnpm-install-o...
Go encourages package authors to simply link to their git repository. It is quite literally cloning source files onto your computer without much thought
It’s ripe for an exploit
I stopped using npm a while back and push and pull tar files instead.
Naturally I get js modules from npm in the first place, but I never run code with it after initial install and testing of a library for my own use.
The de facto compromise is to use package.json for deps, but your distributable blob is a docker image, which serializes a concrete node_modules. Something similar (and perhaps more elegant) is Java's "fat jar" approach where all dependencies are put into a single jar file (and a jar file is just a renamed zip so it's much like a tarball).
If you vendor and tar your dependencies correctly you could functionally build a system around trust layers by inspecting hashes before allowing unpacking for instance.
It’s a thought exercise certainly but there might be legs to this idea
Only Java, .Net and R just download files, at a declared (reproducible) version.
You can set a custom security policy to block or warn on file system, network, shell, or environment variable access.
But the result of a compiler will run on the machine anyway, but once again, it should be in a Docker.
Container technology is awesome, and it’s a huge step forward for the industry, but are places where it’s not feasible to use, at least for now.
Even KVM escapes have been demonstrated. KVM is not a security boundary ... except that in practice it is (a quite effective one at that).
Taken to the extreme you end up with something like "network connected physical machines aren't a security boundary" which is just silly.
Much better.
Open source at least has the option to audit; closed source (or "closed build" stuff like 7zip) is at far higher risk: mostly just VirusTotal which mostly will not catch backdoors of this type.
Mainland China, Russia, North Korea, use these vectors for corporate and government espionage: https://www.youtube.com/watch?v=y27B-sKIUHA ...XZ, Swoole are 2 examples off the top of my head.
Possibly more importantly, it has a security model that defends against this kind of exploit.
I will agree with the sentiment though, I get not wanting to jump on new shiny things but for some reason I keep getting the vibe that the community is closer to crab mentality than healthy skepticism, downright hostile towards any project making a genuine effort to improve things.
That does not feel like a sustainable ecosystem where the incentives are misaligned (wanting a return on capital versus proper open engineering).
Haven't reviewed code but article says its entry point is install script. install scripts don't run on import. I guess you saying it triggers from import too.
At least it's not the cursed javascript, right...
Contrast this to Java, C#, and Python, where you can write robust applications with just the standard libraries.
Other gems exist in the NPM world like is-odd, isarray, and is-negative-zero.
The whole ecosystem developed this absurd culture of micro-packages that all do something insanely trivial that's built-in to pretty much every other language. All of it is a result of trying to force the web into doing things it was never really designed for or meant to do.
Browsers were never supposed to be full application runtimes, and yet we (as an industry) keep doubling down on it
Web technologies are multi-platfrorm, widely accessible, has an unmatched UI API, has great tooling and a large ecosystem. It's the path of least resistance.
Contrast this with something like Qt, which is an absolute pain to compile and is riddled with bugs. It's GUI library is mature, but nowhere near the web.
Time is money, and developers are many times more expensive than the extra cpu cycles the web consumes.
The modus operandi is to add a semi-useful package to a popular project, and then divide said project into other sub-projects just to bump the numbers.
Then those individuals start claiming that they have "25 packages that are foundational to the web infrastructure", while in fact it's just a spinner that has 24 dependencies, some of those being one-liner packages.
Parallel to that we also have things like Babel, which has hundreds of packages, a huge chunk of them being almost empty and only triggering flags in the core package.
Unfortunately all the proprietary OS vendors want to prevent the development of fully portable runtimes, so we've ended up where the browser is the only fully portable application runtime.
– The JavaScript ecosystem moves faster — way more packages, more frequent updates, and more transitive dependencies (avg 79 per package).
– npm has lower barriers to publishing, so it’s easier for malicious actors to get in.
– Java developers often use internal mirrors and have stricter review processes, while npm devs tend to install straight from the registry.
– But to be clear, supply chain attacks do happen in other ecosystems — they’re just underreported. We’ve seen similar issues in PyPI, RubyGems, and even Maven.
JavaScript just happens to be the canary in the coal mine.
[1] https://cloud.google.com/assured-open-source-software/docs/o...
Distressingly, doing what you suggest remains the exception by orders of magnitude. Very few people have internalized why it's necessary and few of those have the political influence in their organizations to make it happen.
- They cache packages but don’t analyze what’s inside.
- They scan or review the first version, then auto-approve every update after that.
- They skip transitive deps — and in npm, that’s 79 on average per package.
- They rely on scanners that claim to detect supply chain attacks but just check for known CVEs. The CVE system doesn’t track malware or supply chain attacks (except rarely), so it misses 99%+ of real threats.
Almost everything on the market today gives a false sense of security.
One exception is Socket — we analyze the actual package behavior to detect risks in real time, even in transitive deps. https://socket.dev (Disclosure: I’m the founder.)
Maybe some do, but you give the average malware developer way too much credit.
and Microsoft own Github so Microsoft is the provider? Pretty sure they're running malware scanners over NPM constantly at the least. NPM also has (optional) provenance [2] to a Github build workflow which is as strong as being "assured" by Google IMO. Only problem is it's optional.
[1]: https://en.wikipedia.org/wiki/Npm [2]: https://github.blog/security/supply-chain-security/introduci...
There’s also alternate implementations of crev [2] for other languages, but I’m not sure about the maturity of those integrations and their ecosystems.
[0] https://github.com/crev-dev/cargo-crev
Apples and oranges and this is far, far worse.
You can absolutely ship signed, trusted code over standard HTTP. Microsoft did this for years and Debian and OpenBSD to name a few still do.
HTTPS does not assure provenance of code.
Anyone who doesn't understand this is very misinformed about what HTTPS does and doesn't do.
There's a deeper issue though. I frequently have difficult getting things to build from source in a network isolated environment. That's after I manually wrangle all the dependencies (and sub-deps, and sub-sub-deps, and ...).
Even worse is something like emscripten where you are fully expected to run `npm install`.
Any build process that depends on network access is fundamentally broken as far as I'm concerned.
You can cache and/or emulate the network to go offline but fundamentally a fresh build in most languages will want to hit a network at least by default
The real problem is that some language ecosystems conflate those two steps.
Even in C/C++ after changing the relevant parameters to non-default values things often break. It seems those configurations often go untested.
Google managed repos are a nice exception to this. Clearly documented commit hashes for all dependencies for a given release.
You could do tls offloading at your load balancer but then you have to secure your entire network starting with your isp. For some workloads, this is fine, you aren’t dealing with super sensitive data. For others, you are violating compliance.
(Disclosure: I’m the founder. https://socket.dev)
This is why, lol.
At times, complexity is worth the trade-offs. Modern C++ compilers are more complex than ones in the 80s and 90s, but the assembly code they generate runs much faster. Rust is complex but provides massive security benefits while maintaining great performance.
At times though, stuff is just bloated or poorly designed.
But it's not always clear how to intelligently design a project. If you add too many features to a single large project, it becomes unwieldy to maintain that large project, and the harder it is to audit this critical piece of infrastructure. Yet, if you don't add enough features, people will use packages from random devs, risking their own security, while harming the maintainability of their own project.
I don't know how we solve that problem. Alternatively, you could ask devs to reinvent the wheel and write a lot more code on their own (which they probably won't, either because they don't want to, or because the employer requires a solution on too short of a timeline to do so), but that could also jeopardize security. Many if not most web devs have to deal with authentication and encryption, both of which (the overwhelming majority) very much should not do on their own. Good luck asking a junior dev to correctly implement AES-256 encryption (or something equivalent or better) on their own without using existing libraries.
The answer is almost certainly some kind of mix, but it's not clear what exactly that should look like.
In fact the only repo I know of doing any checking is Java’s Maven/Sonotype and it’s automated not manual.
Goes the same for almost all packages in all distros though.
I’d say most of us have some connection to what we’re packaging but there are plenty of hastily approved and merged “bump to version x” commits happening.
I don't think this would be viable if the OCaml community grew larger though.
Painless package management is a good thing. Central package repositories without any checking isn't. You don't have to throw away the good because of the bad.
Then "walled garden" became a pejorative, and well… here we are.
A solution is for ID.me to begin issuing developer certificates (for free to those offering themselves up as developers) and for the old system of public repositories and mirrors to be replaced by a single source of truth operated by a new entity jointly sponsored by the $15.4 Trillion worth of companies: Amazon, Google, Meta, Apple, nVidia, Tesla and Microsoft in such a way that everything in every repository can be traced back to the actual biometric signature of a developer and their related IRL context. These entity, its sponsors and ID.me also need to observe a regulation that they will NOT "track" or share information between each other (or others) about developers indexed off their developer certificates beyond what's necessary to host the repositories and to manage access to developer-only programs (such as Xcode signing, etc.) Ideally the JV will be located in Switzerland (perhaps with the hardware located in a Svalbard-like facility) using some UN supervised process (overseen by Nato, Russia, China and the Plebeians) to vet all workers.
It is the curse of all out-of-band package managers... where eventually some lamer shows up to ruin the fun for everybody. =3
The entire idea that 'postinstall' or 'preinstall' or any sort of _script_ needs to run after you've fetched a package of what should be /interpreted/ code is completely insane on any "modern" desktop OS.
From what I can tell the main use case is avoiding the problems from users who cannot figure out how to set an environment variable or reliably run a subshell.
Actually, just rewrite all the packages on npm in rust and that will automatically get rid of any security problem.