node_modules parent climbing is a security risk #8830
Description
node climbs up to find modules, even in places like /home/node_modules
, /node_modules
, or C:\node_modules
on Windows. The Windows case is particularly problematic because any user can create a directory in C:\
.
This has been brought up before:
https://groups.google.com/forum/#!searchin/nodejs/node_modules$20security/nodejs/5BGr5dliUIk/abJEH3sPymcJ
Whether you like the behavior or not, node is compromising the security of multi-user servers and desktops. A shared hosting provider shouldn't need to know that they need to blacklist a "node_modules" username, and developers on Windows shouldn't need to create and secure a C:\node_modules
directory before developing or running node.js software.
Here's a straw man proposal: by default, blacklist certain paths: /node_modules
and C:\node_modules
. If running inside $HOME, don't climb up outside $HOME (this effectively blacklists /home/node_modules
and C:\Users\node_modules
). Also, avoid loading from directories that appear to allow anyone to write to them. For the few exotic deployments out there, expose node's original search behavior behind an argument.