Skip to content

Commit

Permalink
Fix node_modules directory search security risk
Browse files Browse the repository at this point in the history
  • Loading branch information
iankronquist committed Dec 16, 2014
1 parent 350d6e8 commit 095e605
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ Module._nodeModulePaths = function(from) {
// to be absolute. Doing a fully-edge-case-correct path.split
// that works on both Windows and Posix is non-trivial.
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//;
var home_dir = process.env[
(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
var paths = [];
var parts = from.split(splitRe);

Expand All @@ -220,6 +222,8 @@ Module._nodeModulePaths = function(from) {
if (parts[tip] === 'node_modules') continue;
var dir = parts.slice(0, tip + 1).concat('node_modules').join(path.sep);
paths.push(dir);
// If we have reached the user's home directory, stop searching
if (parts.slice(0, tip + 1).join(path.sep) == home_dir) break;
}

return paths;
Expand Down

0 comments on commit 095e605

Please sign in to comment.