mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
lib,permission: support fs.lstat
PR-URL: https://github.com/nodejs-private/node-private/pull/486 Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/604 CVE-ID: CVE-2024-22018
This commit is contained in:
1 parent
d38ea17341
commit
025cbd6936
3 files changed
+36
-6
No files matched your search
@@ -1554,6 +1554,10 @@ function lstat(path, options = { bigint: false }, callback) {
|
||||
}
|
||||
callback = makeStatsCallback(callback);
|
||||
path = getValidatedPath(path);
|
||||
if (permission.isEnabled() && !permission.has('fs.read', path)) {
|
||||
callback(new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', path));
|
||||
return;
|
||||
}
|
||||
|
||||
const req = new FSReqCallback(options.bigint);
|
||||
req.oncomplete = callback;
|
||||
@@ -1630,6 +1634,9 @@ function fstatSync(fd, options = { bigint: false }) {
|
||||
*/
|
||||
function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
|
||||
path = getValidatedPath(path);
|
||||
if (permission.isEnabled() && !permission.has('fs.read', path)) {
|
||||
throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', path);
|
||||
}
|
||||
const stats = binding.lstat(
|
||||
pathModule.toNamespacedPath(path),
|
||||
options.bigint,
|
||||
|
||||
@@ -1113,7 +1113,11 @@ module.exports = {
|
||||
// Note: Node.js specific errors must begin with the prefix ERR_
|
||||
|
||||
E('ERR_ACCESS_DENIED',
|
||||
'Access to this API has been restricted. Permission: %s',
|
||||
function(msg, permission = '', resource = '') {
|
||||
this.permission = permission;
|
||||
this.resource = resource;
|
||||
return msg;
|
||||
},
|
||||
Error);
|
||||
E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);
|
||||
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable', TypeError);
|
||||
|
||||
Vendored
+24
-5
@@ -161,23 +161,23 @@ const regularFile = __filename;
|
||||
}, common.expectsError({
|
||||
code: 'ERR_ACCESS_DENIED',
|
||||
permission: 'FileSystemRead',
|
||||
// cpSync calls statSync before reading blockedFile
|
||||
resource: path.toNamespacedPath(blockedFolder),
|
||||
// cpSync calls lstatSync before reading blockedFile
|
||||
resource: path.toNamespacedPath(blockedFile),
|
||||
}));
|
||||
assert.throws(() => {
|
||||
fs.cpSync(blockedFileURL, path.join(blockedFolder, 'any-other-file'));
|
||||
}, common.expectsError({
|
||||
code: 'ERR_ACCESS_DENIED',
|
||||
permission: 'FileSystemRead',
|
||||
// cpSync calls statSync before reading blockedFile
|
||||
resource: path.toNamespacedPath(blockedFolder),
|
||||
// cpSync calls lstatSync before reading blockedFile
|
||||
resource: path.toNamespacedPath(blockedFile),
|
||||
}));
|
||||
assert.throws(() => {
|
||||
fs.cpSync(blockedFile, path.join(__dirname, 'any-other-file'));
|
||||
}, common.expectsError({
|
||||
code: 'ERR_ACCESS_DENIED',
|
||||
permission: 'FileSystemRead',
|
||||
resource: path.toNamespacedPath(__dirname),
|
||||
resource: path.toNamespacedPath(blockedFile),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -385,4 +385,23 @@ const regularFile = __filename;
|
||||
permission: 'FileSystemRead',
|
||||
resource: path.toNamespacedPath(blockedFile),
|
||||
}));
|
||||
}
|
||||
|
||||
// fs.lstat
|
||||
{
|
||||
assert.throws(() => {
|
||||
fs.lstatSync(blockedFile);
|
||||
}, common.expectsError({
|
||||
code: 'ERR_ACCESS_DENIED',
|
||||
}));
|
||||
assert.throws(() => {
|
||||
fs.lstatSync(path.join(blockedFolder, 'anyfile'));
|
||||
}, common.expectsError({
|
||||
code: 'ERR_ACCESS_DENIED',
|
||||
}));
|
||||
|
||||
// doesNotThrow
|
||||
fs.lstat(regularFile, (err) => {
|
||||
assert.ifError(err);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user