News for hackers. Stuff that matters.
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by easton on Wednesday February 10, 2021 @10:38AM (#26090578)
I believe that Deno (the "successor" to Node being written by Ryan Dahl) is supposed to fix this for server-side JavaScript/TypeScript. It doesn't grant any permissions to anything unless you specifically give them out (so you can say that only a specific module gets access to the filesystem, for instance, and on top of that it can only access /srv and not /etc).

https://deno.land/[email protected]/getting_started/permissions

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by ryukafalz on Wednesday February 10, 2021 @10:57AM (#26090873)
This looks like it's... getting there, but still too coarse-grained. It looks like those permissions are granted to the whole Deno process? So if your program needed both access to sensitive data on the filesystem and network access, and it used a malicious dependency, that dependency could take advantage of those permissions and exfiltrate that data.

I could be wrong, but I don't see any mention of permissions on imported code: https://deno.land/[email protected]/examples/import_export

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by jonny_eh on Wednesday February 10, 2021 @11:11AM (#26091050)
You're right. Deno only has app-level permissions. We need module level too.
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by kevincox on Wednesday February 10, 2021 @12:39PM (#26092270)
I think it could be something like only the root module could import net, fs, os... then in order for modules to access those things the root module would need to pass it in explicitly. Of course if you don't import the module at all there is no access.

Of course JS isn't a great language for this. A malicious program could spider the object graph looking for something valuable. You would have to be very careful to keep these objects hidden. And a container library would have huge amounts of access with it needs none. (For example if you want to store a hashmap of open sockets)

A stronger typed language like Rust or Haskell could do better, as you container library can be prevented from casting T to File. However even that is not enough as you can just manually cast a pointer if you somehow know what type it is. (And there is a small amount of reflection that can do this even in safe code).

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by jonny_eh on Wednesday February 10, 2021 @12:43PM (#26092327)
> Of course JS isn't a great language for this. A malicious program could spider the object graph looking for something valuable.

Deno can provide extra syntax or annotations for imports to allow the dev to explicitly allow permission per-import. These can be in the source code, or in a config file.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by kevincox on Wednesday February 10, 2021 @12:50PM (#26092426)
How would this work exactly? How do you control what module's permission to use for any IO?

For example what if you have a callback library that calls a function that does IO? What if you pass an IO function directly as a callback? (For example File.close) If it is the file where the call is textually written how do you handle dynamic calls? (or are they forbidden).

I think the capability model is probably the right one here.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by korijn on Wednesday February 10, 2021 @05:07PM (#26095447)
Wether controls are coarse or fine (all the way to function level, or even line by line), you still need to audit the source code to see if a package is not going to abuse the permissions you grant it. Right?
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by ryukafalz on Wednesday February 10, 2021 @05:50PM (#26095905)
Not to nearly the same extent; the key is to not grant unnecessary authority in the first place.

Let's say I'm using a `left-pad` function that someone else wrote, and I'm using a system in which modules aren't granted any authority except what you give them. If I then call

  left-pad('foo', 5')
...I don't really have to worry that it'll go rummaging around my filesystem for my private keys and exfiltrate them somewhere. After all, I didn't give it access to my filesystem or the network! (Side-channel attacks notwithstanding, things get thorny real quick at that point.)

Now, you still have to worry about the function not doing what being correct - it might return an empty string, it might go into an infinite loop, etc - but you've tremendously reduced the scope of what this module could do if the developer were malicious.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by korijn on Thursday February 11, 2021 @05:39PM (#26108361)
In obvious cases like that, I agree with you. In real life however my dependencies are rarely that simple.

So let's imagine a REST API library that needs disk and network access to do it's work. How do I know it doesn't abuse my permission?

And what about its transient dependencies?

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by jonny_eh on Thursday February 11, 2021 @06:18PM (#26108843)
But why would a REST API library need disk access? If it required that, it would raise suspicion for me.
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by korijn on Friday February 12, 2021 @05:04PM (#26119083)
Maybe it support serving files (static content)? Or writing them to disk? Either way can we rather argue the point instead of the example?
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by h1fra on Wednesday February 10, 2021 @11:57AM (#26091697)
yes while it goes in the right direction in theory, in practice it provides "almost" no additional security.

the only good differentiator right now that could definitely be implemented in nodejs directly is the the flag `--allow-net=<domain>`. it could prevent data exfiltration but requires the whole stack to require this flag.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by nogbit on Wednesday February 10, 2021 @10:54AM (#26090832)
I think this is critical. The actual runtime of any code needs to do way more than what it’s doing now.

Simply relying on package signing and the like permits trusted but malicious actors. With Deno packages configured well it can really lock down and limit a ton of attack vectors.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by salawat on Wednesday February 10, 2021 @02:30PM (#26093575)
>trusted but malicious actors

I...think you might have bigger problems going on there. You're tryingto throw a tech solution at a problem that is fundamentally human in nature.

That tends to leave nobody satisfied.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by josephg on Wednesday February 10, 2021 @02:53PM (#26093830)
Tech solutions are the best solutions when they work! Fighting with your spouse over who does the dishes? Buy a dishwasher! Don’t want your ISP snooping on traffic? Use https / a VPN!

Unfortunately, package signing does nothing to protect against the threat vector presented here. The authentication system in npm is working fine. The problem is we put too much trust in software from the internet.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by salawat on Wednesday February 10, 2021 @04:51PM (#26095285)
...Hence my classification of it as a human problem. I apologize, this is a quirk of my personal vernacular. This is a problem that emergently arises out of the way human beings interact with each other socially, even before tool use comes into the picture.

Alice has a thing. Bob had a thing that Alice figured would make her life easier so integrates it without looking too hard at it. Alice didn't reallize that by adding Bob's thing, something Alice wanted private was no longer the case even if her primary use case was solved.

The technical solution is making Alice's thing include a really onerous to configure permissions framework that takes the work of getting a thing set up and increases the task list from program thing to program and configure permissions for thing.

The human solution is to realize you don't know Bob from Adam, or his motivations, and to observe what Bob's thing actually does. Then depending on criticality, remake something similar, or actually take the time to get to know Bob and see if he can make what you want for you under some sort of agreement that facilitates good business and trust all around. You can't be sampling for malicious changes in real-time, so it's all about risk management. The issue in our case, is a lot of these projects are essentially gifts with no active attention paid to them after a certain point. It's a variant of cargo cults. You want this thing? Go here, get that, presto. Businesses, developers, (and their exploiters) like that. The price though is that once a project is abandoned, and the rights transferred to someone you don't know, you have to rerun your risk management calculation again.

The thing people should be worried about is all the PHB's (pointy-haired bosses) who just got ammo for their NMIH (Not-Made-In-House) cannons now that supply chain attacks are becoming increasingly visible vectors for attack.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by salawat on Wednesday February 10, 2021 @06:09PM (#26096113)
In a rare self-reply, this feeds into the reason why I scratch my head at the whole license based IP distribution thing.

By bringing licenses into it, you push for a business relationship first, but discourage further toolmaking. Programs are math. Rederivation and application should really be the norm, but can't be if we're drawing boxes around arrangements of symbols and saying "Do not cross."

It's the weird contradiction at the core of what we do as software people that still keeps me scratching my head. We all run to make a hydrant to mark, then try to make rent extracting business around it instead of maximizing the number of variants of hopefully practical and efficient ways to allow everyone else to solve their own problems.

I'm not against people being able to make a living doing what they love, but the incentive structure seems all out of jibe with what I understood to be the overall goal.

Or something. Still wrapping my head around it I guess.

Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by Gehinnn on Wednesday February 10, 2021 @05:00PM (#26095384)
What about reviews and review certificates then? If you review a the package [email protected] you could publicly certify that it is not malicious and maybe earn some money with it. In turn, you back your claim with a financial security that you pay in case the package actually contains malicious code.
Re:Dependency Confusion: How I Hacked Into Apple, Microsoft ... by josephg on Wednesday February 10, 2021 @07:48PM (#26096868)
Thats a great idea - but in a centralized system like npm or cargo you don't need certificates to implement that. (Certs might be a nice implementation though.)

So yeah, there might be a "trusted security reviews with payments" shaped technical solution. I'd love to see someone flesh that out - that sounds like a potential solution to this problem (unlike developer-signed packages).