News for hackers. Stuff that matters.
Re:Understand filesystem takeover vulnerabilities in NPM Jav... by tomxor on Wednesday January 08, 2020 @07:45AM (#21990874)
> What surprised me was that the "bin" names can be a relative or absolute path, like:

> "bin": { "/usr/bin/date": "./fake-date" }

This will only possibly work if you install it with root privileges... at which point you need to have a reasonable level of trust of the script you are running. It's unreasonable to give the same level of trust to npm packages that you do your OS package manager since anyone can publish an npm package without anyone elses permission.

For this reason I think npm's defaults are a really shitty choice (global prefix under root). I always change the global prefix to live in my user directory for this reason so I can npm install -g without root:

    sudo npm config -g set prefix '~/.local'
You will need to add the local bin to your PATH (if it doesn't already contain it)

    PATH="$HOME/.local/bin:$PATH"
The order above is important, local must come before existing PATHs for lower precedence so that it cannot override higher privilege bins... e.g so that if an npm package added a bin for '~/.local/bin/cat', it would never be called implicitly since '/usr/bin/cat' exists.
Re:Understand filesystem takeover vulnerabilities in NPM Jav... by ryukafalz on Wednesday January 08, 2020 @08:34AM (#21991248)
>The order above is important, local must come before existing PATHs for lower precedence so that it cannot override higher privilege bins

You've got the order reversed there - the first item found in your PATH will be used, and therefore earlier directories in your PATH have higher precedence:

  jfred@lambdacrypt ~$ cat dir1/pathtest 
  #!/run/current-system/profile/bin/bash
  echo "script in dir1"
  jfred@lambdacrypt ~$ cat dir2/pathtest 
  #!/run/current-system/profile/bin/bash
  echo "script in dir2"
  jfred@lambdacrypt ~$ PATH=$HOME/dir1:$HOME/dir2 pathtest
  script in dir1
Re:Understand filesystem takeover vulnerabilities in NPM Jav... by tomxor on Wednesday January 08, 2020 @09:35PM (#21998019)
You are correct my mistake.
Re:Understand filesystem takeover vulnerabilities in NPM Jav... by inimino on Wednesday January 08, 2020 @08:59AM (#21991452)
I don't understand the point in using ~/.local/bin and then putting it in your PATH. The point of treating /usr/local/bin and the other root-owned binary directories specially is that they are in your path, which means that if you type "ls" you want to run "ls" and not something untrusted. For that reason, anything you put in your PATH needs to be treated exactly with as much care as anything you install in /bin. The only difference might be that you don't affect other users on the same system, in a multi-user environment (which is increasingly rare). It might be convenient if you wanted to be able to clean up an entire installation by deleting one directory, but it's not a security feature.

Don't install binaries anywhere in your path if you don't trust them or know where they came from. (Also, sibling is correct that first location found wins when searching PATH for a command name.)

Also, it's not unreasonable to trust npm packages just like OS packages if you know who released it. NPM names are first-come, first-served, and once allocated, they are permanent. If you know and trust the person who released the package, there's nothing wrong with trusting the package. This was, in fact, the norm when npm was new and the community was small and most people knew each other. The only problem is with treating npm like a vetted distro like Debian, and assuming that anything on npm is safe to install without any connection to the author (or 1001 dependencies). That's where everything started to go sideways.

Re:Understand filesystem takeover vulnerabilities in NPM Jav... by tomxor on Wednesday January 08, 2020 @09:44PM (#21998062)
> anything you put in your PATH needs to be treated exactly with as much care as anything you install in /bin. [...] it's not a security feature.

The parent was highlighting how the article points out you can overwrite root files:

> "bin": { "/usr/bin/date": "./fake-date" }

This is not possible with ~/.local

I wouldn't call this a "security feature", but I would call it prudent to not hand over root access to npm packages.

> Also, it's not unreasonable to trust npm packages just like OS packages if you know who released it. NPM names are first-come, first-served, and once allocated, they are permanent. If you know and trust the person who released the package, there's nothing wrong with trusting the package.

This is not the problem with npm, the problem is dependencies, and their dependencies and so on. I certainly will never be able to personally vet the 1000 deep nest of dependencies in an npm package I may have to use.

Re:Understand filesystem takeover vulnerabilities in NPM Jav... by WorldMaker on Wednesday January 08, 2020 @03:38PM (#21995529)
It seems another reason to prefer `npx` over `npm install -g`.