4 ms·
Whoa, I didn't know about this: # Run with restricted file system access node --experimental-permission \ --allow-fs-read=./data --allow-fs-write=./log
by simonw 1y ago
Whoa, I didn't know about this:
# Run with restricted file system access
node --experimental-permission \
--allow-fs-read=./data --allow-fs-write=./logs app.js
# Network restrictions
node --experimental-permission \
--allow-net=api.example.com app.js
Looks like they were inspired by Deno. That's an excellent feature. https://docs.deno.com/runtime/fundamentals/security/#permissions https://docs.deno.com/runtime/fundamentals/security/#permiss...
- kijin 1y agoPath restrictions look simple, but they're very difficult to implement correctly. PHP used to have (actually, still has) an "open_basedir" setting to restrict where a script could read or write, but people found out a number of ways to bypass that using symlinks and other shenanigans. It took a while for the devs to fix the known loopholes. Looks like node has been going through a similar process in the last couple of years. Similarly, I won't be surprised if someone can use DNS tricks to bypass --allow-net restrictions in some way. Probably not worth a vulnerability in its own right, but it could be used as one of the steps in a targeted attack. So don't trust it too much, and always practice defense in depth!
- int_19h 1y agoLast time a major runtime tried implementing such restrictions on VM level, it was .NET - and it took that idea from Java, which did it only 5 years earlier. In both Java and .NET VMs today, this entire facility is deprecated because they couldn't make it secure enough.
- arccy 1y agoI believe that the various OSes have implemented appropriate syscalls such as openat to support it e.x. https://go.dev/blog/osroot https://go.dev/blog/osroot
- kijin 1y agoEven that doesn't protect you from bind mounts. The rationale seems to be that only root can create bind mounts. But guess what, unprivileged users can also create all sorts of crazy mounts with fuse. The whole idea of a hierarchical directory structure is an illusion. There can be all sorts of cross-links and even circular references.
- tankenmate 1y agoI wouldn't trust it to be done right. It's like a bank trusting that all their customers will do the right thing. If you want MAC (as opposed to DAC), do it in the kernel like it's supposed to be; use apparmor or selinux. And both of those methods will allow you to control way more than just which files you can read / write.
- bombela 1y agoYeah but you see, this requires to be deployed along side the application somehow with the help of the ops team. While changing the command line is under control of the application developer.
- tankenmate 1y agoSo security theatre is the best option? I'm not saying this to be cheeky, but it just seems to be an overly shallow option that is trivially easy to end run.
- bombela 1y agoAgreed. How can we offer a solution that is as low or lower friction and does the right thing instead of security theater. At least we could consider this part of a defense in depth. We; humans; always reach for instant gratification. The path of low resistance is the one that wins.
- motorest 1y ago> I wouldn't trust it to be done right. I don't understand this sort of complaint. Would you prefer that they didn't worked on this support ever? Exactly what's your point? Airing trust issues?
- throwup238 1y agoNode allows native addons in packages via the N-API so any native module aren't restricted by those permissions. Deno deals with this via --allow-ffi but these experimental Node permissions have nothing to disable the N-API, they just restrict the Node standard library.
- berkes 1y agoI very much dislike such features in a runtime or app. The "proper" place to solve this, is in the OS. Where it has been solved, including all the inevitable corner cases, already. Why reinvent this wheel, adding complexity, bug-surface, maintenance burden and whatnot to your project? What problem dies it solve that hasn't been solved by other people?
- chii 1y ago> What problem does it solve that hasn't been solved by other people? nothing. Except for "portability" arguments perhaps. Java has had security managers and access restrictions built in but it never worked very well (and is quite cumbersome to use in practice). And there's been lots of bypasses over the years, and patch work fixes etc. Tbh, the OS is the only real security you could trust, as it's as low a level as any application would typically go (unless you end up in driver/kernal space, like those anti-virus/anti-cheat/crowdstrike apps). But platform vendors always want to NIH and make their platform slightly easier and still present the similar level of security.
- Cthulhu_ 1y agoHow would you do this in a native fashion? I mean I believe you (chroot jail I think it was?), but not everyone runs on *nix systems, and perhaps more importantly, not all Node developers know or want to know much about the underlying operating system. Which is to their detriment, of course, but a lot of people are "stuck" in their ecosystem. This is arguably even worse in the Java ecosystem, but it's considered a selling point (write once run anywhere on the JVM, etc).
- Deestan 1y ago> but not everyone runs on *nix systems Meaning Windows? It also has file system permissons on an OS level that are well-tested and reliable. > not all Node developers know or want to know much about the underlying operating system Thing is, they are likely to not feel up for understanding this feature either, nor write their code to play well with it. And if they at some point do want to take system permissions seriously, they'll find it infinitely easier to work with the OS.
- captn3m0 1y agoCan't seem to find an official docs link for allow-net, only blog posts.
- tchetwin 1y agohttps://github.com/nodejs/node/pull/58517 https://github.com/nodejs/node/pull/58517 - I think the `semver-major` and the timing mean that it might not be available until v25, around October