Skip to content

Commit

Permalink
permission: ensure to resolve path when calling mkdtemp
Browse files Browse the repository at this point in the history
PR-URL: nodejs-private/node-private#464
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=2037887
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
RafaelGSS committed Aug 9, 2023
1 parent 1f0cde4 commit 98a83a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,7 @@ function mkdtemp(prefix, options, callback) {

validateString(prefix, 'prefix');
nullCheck(prefix, 'prefix');
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);
const req = new FSReqCallback();
req.oncomplete = callback;
Expand All @@ -2933,6 +2934,7 @@ function mkdtempSync(prefix, options) {

validateString(prefix, 'prefix');
nullCheck(prefix, 'prefix');
prefix = getValidatedPath(prefix, 'prefix');
warnOnNonPortableTemplate(prefix);
const path = `${prefix}XXXXXX`;
const ctx = { path };
Expand Down
16 changes: 14 additions & 2 deletions test/fixtures/permission/fs-traversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ const bufferTraversalPath = Buffer.from(allowedFolder + '../file.md');
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.resolve(traversalFolderPath + 'XXXXXX')),
resource: path.resolve(traversalFolderPath + 'XXXXXX'),
}));
}

{
assert.throws(() => {
fs.mkdtemp(traversalFolderPath, (error) => {
assert.ifError(error);
});
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.resolve(traversalFolderPath + 'XXXXXX'),
}));
}

Expand All @@ -72,4 +84,4 @@ const bufferTraversalPath = Buffer.from(allowedFolder + '../file.md');
assert.ok(!process.permission.has('fs.write', traversalPath));
assert.ok(!process.permission.has('fs.read', traversalFolderPath));
assert.ok(!process.permission.has('fs.write', traversalFolderPath));
}
}

0 comments on commit 98a83a6

Please sign in to comment.