Skip to content

Commit 0083071

Browse files
RafaelGSSaduh95
authored andcommitted
permission: add permission check to realpath.native
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: nodejs-private/node-private#838 CVE-ID: CVE-2026-21715
1 parent 2acd5d1 commit 0083071

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/node_file.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,11 +1912,19 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
19121912

19131913
if (argc > 2) { // realpath(path, encoding, req)
19141914
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
1915+
CHECK_NOT_NULL(req_wrap_async);
1916+
ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS(
1917+
env,
1918+
req_wrap_async,
1919+
permission::PermissionScope::kFileSystemRead,
1920+
path.ToStringView());
19151921
FS_ASYNC_TRACE_BEGIN1(
19161922
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
19171923
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
19181924
uv_fs_realpath, *path);
19191925
} else { // realpath(path, encoding, undefined, ctx)
1926+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1927+
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
19201928
FSReqWrapSync req_wrap_sync("realpath", *path);
19211929
FS_SYNC_TRACE_BEGIN(realpath);
19221930
int err =

test/fixtures/permission/fs-read.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,18 @@ const regularFile = __filename;
480480
fs.lstat(regularFile, (err) => {
481481
assert.ifError(err);
482482
});
483+
}
484+
485+
// fs.realpath.native
486+
{
487+
fs.realpath.native(blockedFile, common.expectsError({
488+
code: 'ERR_ACCESS_DENIED',
489+
permission: 'FileSystemRead',
490+
resource: path.toNamespacedPath(blockedFile),
491+
}));
492+
493+
// doesNotThrow
494+
fs.realpath.native(regularFile, (err) => {
495+
assert.ifError(err);
496+
});
483497
}

0 commit comments

Comments
 (0)