Skip to content

Commit

Permalink
module: validate request in require.resolve.paths
Browse files Browse the repository at this point in the history
PR-URL: nodejs#18359
Fixes: nodejs#18352
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joyeecheung authored and MayaLekova committed May 8, 2018
1 parent 89dd70a commit 51c0ff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function makeRequireFunction(mod) {
require.resolve = resolve;

function paths(request) {
if (typeof request !== 'string') {
throw new errors.Error('ERR_INVALID_ARG_TYPE',
'request', 'string', request);
}
return Module._resolveLookupPaths(request, mod, true);
}

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-require-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ const re = /^The "request" argument must be of type string\. Received type \w+$/
code: 'ERR_INVALID_ARG_TYPE',
message: re
});

common.expectsError(
() => { require.resolve.paths(value); },
{
code: 'ERR_INVALID_ARG_TYPE',
message: re
});
});

0 comments on commit 51c0ff6

Please sign in to comment.