-
Notifications
You must be signed in to change notification settings - Fork 7.3k
node_modules parent climbing is a security risk #8830
Comments
I'm taking a look at this. |
I think not searching above the project's |
This appears to have gotten a soft -1 from isaac when it came up on the mailing list at the time. To recap that argument here: a calamity of security flaws have to align to allow a user to compromise your node modules in this fashion:
|
|
I like @robotlolita's suggestion to allow users to specify an optional root. It's a whitelist rather than a blacklist, and it can be enforced absolutely if desired. You could either have it avoid opening any files outside that tree or just indicate that the module search should terminate there (in which case symlinks to other trees would still work, which is useful). I think it would be better to avoid assuming certain policy decisions like blacklisting /node_modules or stopping traversal at $HOME. As others have pointed out, this is not a bug, since it's working as designed and documented[0]. The resulting behavior may make Node today unsuitable for certain environments (and in ways that are not obvious), and I think it makes sense to add a feature to improve that, but I only see this affecting Windows deployments and hosting environments that use a shared, non-isolated filesystem[1]. Both are sad (and shared hosting is sad for security for other reasons), but I don't think it's reasonable to call this a Node security issue any more than it's a security issue that you can specify arbitrary programs on the command line. The functionality in question is just too general-purpose and requires a surrounding system that's configured somewhat dangerously in order to abuse it. [0] http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders [1] On a Unix system, the attacker needs either write access to a parent directory of the victim's application (in which case the victim is completely compromised anyway) or needs to trick an operator into creating a "node_modules" directory in one of those parent directories. The only way I can see to do the latter is creating a home directory. |
There are definitely ways we can improve sandboxing in the future for node. In the meantime you can explore existing mechanisms users are using for locking down the paths that are allowed for require with modules like: https://www.npmjs.com/package/fs-lock |
It's a bit late for this now, but: in the future, if you suspect you have found a security issue, the appropriate venue for responsible disclosure is to email [email protected] with a description of the exploit -- it should not go through github issues. |
I think if we are on a multi-user machine this is something that should be locked down already by the system admin, and creating more complexity to the module loader is... a bad idea. Per process settings are pretty easy to reset in various ways (env vars can be reset, spawning child processes can get around this). Possible solutions:
Scenario Research:Note: XP (Semi-realistic scenario):
Vista (User creation at fault / Lack of dropping privileges at fault):
7 (User creation at fault / Lack of dropping privileges at fault):
8 (User creation at fault / Lack of dropping privileges at fault):
ConclusionIn Windows XP there is a somewhat realistic scenario where this could occur if someone got guest/anonymous access to a machine. This exploit is limited to created/authenticated users after that. RecommendationUsers should not be able to write to drive root paths by default anyway if you are administering a multi-user machine. Do this regardless of the XP: Immediate removal of Everyone group from roots of drives upon creation Vista - 8: Remove permissions for relevant directories where Users should not be allowed to create folders prior to User creation. |
@joyent/node-coreteam ... any further thoughts on this one? I'm personally leaning towards closing without further action. |
node climbs up to find modules, even in places like
/home/node_modules
,/node_modules
, orC:\node_modules
on Windows. The Windows case is particularly problematic because any user can create a directory inC:\
.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
andC:\node_modules
. If running inside $HOME, don't climb up outside $HOME (this effectively blacklists/home/node_modules
andC:\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.The text was updated successfully, but these errors were encountered: