Skip to content

Commit bfdecef

Browse files
RafaelGSSjuanarbol
authored andcommitted
permission: add permission check to realpath.native
PR-URL: nodejs-private/node-private#794 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> CVE-ID: CVE-2026-21715
1 parent 6521f88 commit bfdecef

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/node_file.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,18 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
19461946
if (argc > 2) { // realpath(path, encoding, req)
19471947
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
19481948
CHECK_NOT_NULL(req_wrap_async);
1949+
ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS(
1950+
env,
1951+
req_wrap_async,
1952+
permission::PermissionScope::kFileSystemRead,
1953+
path.ToStringView());
19491954
FS_ASYNC_TRACE_BEGIN1(
19501955
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
19511956
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
19521957
uv_fs_realpath, *path);
19531958
} else { // realpath(path, encoding, undefined, ctx)
1959+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1960+
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
19541961
FSReqWrapSync req_wrap_sync("realpath", *path);
19551962
FS_SYNC_TRACE_BEGIN(realpath);
19561963
int err =

test/fixtures/permission/fs-read.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,18 @@ const regularFile = __filename;
496496
fs.lstat(regularFile, (err) => {
497497
assert.ifError(err);
498498
});
499+
}
500+
501+
// fs.realpath.native
502+
{
503+
fs.realpath.native(blockedFile, common.expectsError({
504+
code: 'ERR_ACCESS_DENIED',
505+
permission: 'FileSystemRead',
506+
resource: path.toNamespacedPath(blockedFile),
507+
}));
508+
509+
// doesNotThrow
510+
fs.realpath.native(regularFile, (err) => {
511+
assert.ifError(err);
512+
});
499513
}

0 commit comments

Comments
 (0)