Skip to content

Commit db48d9c

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#794 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> CVE-ID: CVE-2026-21715
1 parent 2a6105a commit db48d9c

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
@@ -1849,11 +1849,18 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
18491849
if (argc > 2) { // realpath(path, encoding, req)
18501850
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
18511851
CHECK_NOT_NULL(req_wrap_async);
1852+
ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS(
1853+
env,
1854+
req_wrap_async,
1855+
permission::PermissionScope::kFileSystemRead,
1856+
path.ToStringView());
18521857
FS_ASYNC_TRACE_BEGIN1(
18531858
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
18541859
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
18551860
uv_fs_realpath, *path);
18561861
} else { // realpath(path, encoding, undefined, ctx)
1862+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1863+
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
18571864
FSReqWrapSync req_wrap_sync("realpath", *path);
18581865
FS_SYNC_TRACE_BEGIN(realpath);
18591866
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)