News for hackers. Stuff that matters.
Re:On node-ipc and the importance of trusting trust by ryukafalz on Friday March 25, 2022 @12:03AM (#30798545)
> There is nothing special about computer that allows us to put complete trust into any piece of code, and that is okay. Instead, we strive to build trust among developers so that we don't have to read every line of code in every level of abstraction to make sure our files won't be deleted.

I don't understand why this is so often treated as a dichotomy, where either you trust every single author to not delete your files, or you review every line of code to make sure it doesn't delete your files. Both seem unsustainable. I think we need to look at the problem from a different perspective: why is every single transitive dependency able to delete your files?

Take a look at the node-ipc method reference: https://www.npmjs.com/package/node-ipc#ipc-methods

What functionality does node-ipc have that requires it to have unfettered access to the filesystem? Well, with its current implementation, it needs to be able to create a unix socket for e.g. 'serve()'. But if you changed the API a bit, you could conceivably pass it a file handle to a unix socket that you've just created, instead. Now that module doesn't need any arbitrary filesystem access at all! You could make similar changes to those methods responsible for making outbound network connections, etc. At that point, you could almost completely sandbox this module, because all it needs is what you've given it.

In other words: let's apply the principle of least authority for real.

https://medium.com/agoric/pola-would-have-prevented-the-even...

Re:On node-ipc and the importance of trusting trust by Legogris on Friday March 25, 2022 @12:42AM (#30798718)
If you find this resonates, Lavamoat is basically the continuation of that 2018 blog post. Hopefully it catches on to get enough traction that SES (or something similar enough providing an API for controlling capabilities) makes it into runtimes.

https://github.com/LavaMoat/LavaMoat

https://news.ycombinator.com/item?id=30707096

Re:On node-ipc and the importance of trusting trust by eyelidlessness on Friday March 25, 2022 @12:13AM (#30798583)
There are a lot of people who think subdeps should be able to just assert that they’re not vulnerable at all. It’s a popular idea, enough so it might be implemented in Node. Even though the originator of the idea was receptive to my many objections, the RFC authors were not.

Here’s a thought that’s been living in my head rent free ever since: what if we don’t have transitive dependencies at all? What if we just… package them all up together? That sounds absurd, but we are almost all using a build system, we who are all have sourcemaps and dead code elimination baked in. We can standardize this. The package NPM delivers is already different from the published thing. We can define “this is how you reproduce my build”, and distributors can say “this is what is present in this package” with high confidence. Sourcemaps can deduplicate.

Re:On node-ipc and the importance of trusting trust by vladvasiliu on Friday March 25, 2022 @02:16AM (#30799173)
I'm not very familiar with how Node dependencies work, but isn't this just reshuffling the same card deck?

If package M is malicious, what difference does it make if it's required directly by your app, or through a sub-dependency chain, like A -> B -> C -> M?

If you have an approach that allows you to vet all your direct dependencies, why wouldn't that allow you to vet sub-dependencies as well?

Re:On node-ipc and the importance of trusting trust by eyelidlessness on Friday March 25, 2022 @12:59PM (#30804573)
What I’m proposing is specifically in cases where sub-dependencies may have a known vulnerability but that isn’t in any of the call paths of your direct dependency. It’s an alternative to the “audit assertions”[1] proposal, which I find problematic for reasons I discussed there before I bowed out. My idea is that you can be confident you’re not affected by a vulnerability in a dependency (at any depth), if that vulnerability is no longer in the code in the first place.

It also reduces the surface area to vet in the first place. It’s highly likely many dependencies will be stripped down considerably, if not outright deduplicated or eliminated. The “npm installs thousands of dependencies” thing is a real problem, but it’s also partly because it’s installing stuff you’ll never actually execute in any way.

You can pare down sub-dependencies with confidence, because you already know what code paths are hit by the parent dependency at packaging time. You can’t do that with direct dependencies until you go to package/deploy, because of course you may expand your usage of their APIs during development.

1: https://github.com/npm/rfcs/pull/422

Re:On node-ipc and the importance of trusting trust by vladvasiliu on Friday March 25, 2022 @02:03PM (#30805323)
This sounds like a good idea to me. My shallow understating of the Node ecosystem makes me think of tree-shaking. Is that something else? I was under the impression that it allowed not shipping pieces of the dependencies which are unused, which should help with limiting the surface area to vet.

From my superficial understanding of how this works, couldn't the "build" phase take note which parts of dependencies are loaded, and then compare those with where the known vulnerabilities are? I realize some issues may be bigger or harder to narrow down, but it still looks like it would be a step in the right direction.

Re:On node-ipc and the importance of trusting trust by eyelidlessness on Friday March 25, 2022 @03:47PM (#30806368)
You’re spot on in your understanding of the idea.

I think it could go further than the state of the art tree shaking, by adding deduplication of unchanged code between different versions of the same package. This would mostly be a benefit for shrinking installed dependencies, but that helps make the idea of actually vetting/auditing them a lot more plausible too. And it could help make dealing with semver-incompatible versions more flexible (i.e. if the remaining code is identical, tada now it's semver-compatible because it’s the same code!), somewhat mitigating a common audit resolution blocker.

All of this of course would need some sort of a manifest detailing which code comes from which location(s) in which package(s), and (at least optionally) a human-friendly file system structure that users can actually audit/vet.

If I didn’t already have a backlog of side projects a mile long, I’d probably be working on this already, because there’s a clear need for improvement in this area. But none of it feels outlandishly hard to pull off if anyone wanted to run with the idea.

Re:On node-ipc and the importance of trusting trust by broken8ball on Saturday March 26, 2022 @12:57AM (#30809341)
AFAIK, Deno seeks to solve the most severe case of this problem in Node[0]. At the very least, you start from a place where permission surprises are more readily caught. Would be really great to be able to specify on a per-import basis.

[0] https://deno.land/manual/getting_started/permissions

Re:On node-ipc and the importance of trusting trust by zarzavat on Friday March 25, 2022 @12:55AM (#30798766)
Sandboxed components are good at mitigating attacks from the outside. However they don’t help much against a malicious package author who has a multitude of different ways of causing havoc: while(1); for example. Playing this game of cat and mouse will add so much red tape that nobody will want to use that package manager anymore.

Ultimately package repos run on trust and a low level of risk is tolerated because of the benefits of being able to get stuff done.

Re:On node-ipc and the importance of trusting trust by vladvasiliu on Friday March 25, 2022 @02:12AM (#30799155)
> Playing this game of cat and mouse will add so much red tape that nobody will want to use that package manager anymore.

Of course. But your comment still reads as "we can't make it perfect, so might as well not try at all". I think there can still be value in limiting the blast radius.

Your while(1), if present, is likely to be intentionally malicious. But I've seen many naïve libraries implement "accidentally quadratic" algorithms, which is basically a disguised while(1), but unintentional.

The point is that the end result of `rm -rf /` is painful. It doesn't matter if someone managed to maliciously sneak that into your supply chain, or if it rises from some funky corner case of some package whose only goal is to bring world peace. So being able to prevent some leftpad lib from accessing the file system at all makes a lot of sense.

Re:On node-ipc and the importance of trusting trust by Legogris on Friday March 25, 2022 @03:55AM (#30799629)
> while(1)

In SES, that is controlled by allowing assignment of a budget and failing if it's exceeded. Similar to how gas works in the EVM.

Re:On node-ipc and the importance of trusting trust by nindalf on Friday March 25, 2022 @01:28AM (#30798921)
Mitigation strategies

while(1) - kill -9 / Task Manager / Activity Monitor

All files deleted - cry.

Re:On node-ipc and the importance of trusting trust by klabb3 on Friday March 25, 2022 @12:48AM (#30798738)
Sure, but languages aren't designed to provide secure isolation on a module-by-module level. The encapsulation that exists (e.g. private fields) isn't for security.

Or is there some security feature of node or JS that I'm missing?

Re:On node-ipc and the importance of trusting trust by ryukafalz on Friday March 25, 2022 @07:53AM (#30800972)
You’re right that in most languages, encapsulation isn’t strong enough to be used for security in this way. However, there are languages in which it is; scheme I believe has strict enough lexical scope and encapsulation to be used like this. (And of course there are languages designed specifically for this purpose, though they’re not often used: E and Monte come to mind.)

Of the popular languages, though, JavaScript is the closest to being strict enough for this style of programming, and there’s been active work for a while towards that goal:

https://agoric.com/blog/technology/ses-securing-javascript/

Re:On node-ipc and the importance of trusting trust by pabs3 on Friday March 25, 2022 @05:07AM (#30799969)
Distributed code review might tradeoff between trusting authors vs reviewing everything yourself.

https://github.com/crev-dev/

Re:On node-ipc and the importance of trusting trust by weq on Friday March 25, 2022 @12:21AM (#30798628)
Totally agree with this. People think because your code is popular it means its good. API surface area stuff like this causes crypto heists everyday.