From db48d9c675103f7675cf4b7769e5edba842f03ea Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 5 Jan 2026 18:18:39 -0300 Subject: [PATCH] permission: add permission check to realpath.native MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RafaelGSS PR-URL: https://github.com/nodejs-private/node-private/pull/794 Reviewed-By: Anna Henningsen Reviewed-By: Marco Ippolito Reviewed-By: Juan José Arboleda Reviewed-By: Matteo Collina CVE-ID: CVE-2026-21715 --- src/node_file.cc | 7 +++++++ test/fixtures/permission/fs-read.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/node_file.cc b/src/node_file.cc index 6ed00e0c173..efa43d01576 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1849,11 +1849,18 @@ static void RealPath(const FunctionCallbackInfo& 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 = diff --git a/test/fixtures/permission/fs-read.js b/test/fixtures/permission/fs-read.js index 22f4c4184ae..fa2bc14e443 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -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); + }); } \ No newline at end of file