permission: add permission check to realpath.native

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/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
This commit is contained in:
RafaelGSS authored and Antoine du Hamel committed 2026-03-22 17:04:56 +01:00
1 parent 2a6105a63b
commit db48d9c675
2 files changed
+21

No files matched your search

+7
View File
@@ -1849,11 +1849,18 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
if (argc > 2) { // realpath(path, encoding, req)
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
CHECK_NOT_NULL(req_wrap_async);
ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS(
env,
req_wrap_async,
permission::PermissionScope::kFileSystemRead,
path.ToStringView());
FS_ASYNC_TRACE_BEGIN1(
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
uv_fs_realpath, *path);
} else { // realpath(path, encoding, undefined, ctx)
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
FSReqWrapSync req_wrap_sync("realpath", *path);
FS_SYNC_TRACE_BEGIN(realpath);
int err =
+14
View File
@@ -496,4 +496,18 @@ const regularFile = __filename;
fs.lstat(regularFile, (err) => {
assert.ifError(err);
});
}
// fs.realpath.native
{
fs.realpath.native(blockedFile, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFile),
}));
// doesNotThrow
fs.realpath.native(regularFile, (err) => {
assert.ifError(err);
});
}