From ccac5ce3081951f8b0b552d824d7a4ccb7a93528 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 23 Oct 2026 14:37:55 -0300 Subject: [PATCH 1/2] fs: suggest --allow-fs-read in lstat permission errors This was missed in #57585. Signed-off-by: RafaelGSS --- doc/api/cli.md | 6 +++--- doc/api/permissions.md | 2 +- doc/node.1 | 6 +++--- lib/fs.js | 16 ++++++++++++---- lib/internal/fs/promises.js | 6 +++++- test/fixtures/permission/fs-read.js | 21 +++++++++++++++++++++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 6a8b3756fe72..778f4a6b9a98 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -173,7 +173,7 @@ $ node --permission --allow-fs-read=* index.js node:internal/child_process:388 const err = this._handle.spawn(options); ^ -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-child-process to manage permissions. at ChildProcess.spawn (node:internal/child_process:388:28) at node:internal/main/run_main_module:17:47 { code: 'ERR_ACCESS_DENIED', @@ -488,7 +488,7 @@ new WASI({ ```console $ node --permission --allow-fs-read=* index.js -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-wasi to manage permissions. at node:internal/main/run_main_module:30:49 { code: 'ERR_ACCESS_DENIED', permission: 'WASI', @@ -519,7 +519,7 @@ new Worker(__filename); ```console $ node --permission --allow-fs-read=* index.js -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-worker to manage permissions. at node:internal/main/run_main_module:17:47 { code: 'ERR_ACCESS_DENIED', permission: 'WorkerThreads' diff --git a/doc/api/permissions.md b/doc/api/permissions.md index 45e2c7679ae5..25684985987f 100644 --- a/doc/api/permissions.md +++ b/doc/api/permissions.md @@ -68,7 +68,7 @@ restricted (the listener for SIGUSR1 won't be created). ```console $ node --permission index.js -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-fs-read to manage permissions. at node:internal/main/run_main_module:23:47 { code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead', diff --git a/doc/node.1 b/doc/node.1 index 05fc5418e474..e26957a8bdba 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -102,7 +102,7 @@ $ node --permission --allow-fs-read=* index.js node:internal/child_process:388 const err = this._handle.spawn(options); ^ -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-child-process to manage permissions. at ChildProcess.spawn (node:internal/child_process:388:28) at node:internal/main/run_main_module:17:47 { code: 'ERR_ACCESS_DENIED', @@ -308,7 +308,7 @@ new WASI({ .Bd -literal $ node --permission --allow-fs-read=* index.js -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-wasi to manage permissions. at node:internal/main/run_main_module:30:49 { code: 'ERR_ACCESS_DENIED', permission: 'WASI', @@ -329,7 +329,7 @@ new Worker(__filename); .Bd -literal $ node --permission --allow-fs-read=* index.js -Error: Access to this API has been restricted +Error: Access to this API has been restricted. Use --allow-worker to manage permissions. at node:internal/main/run_main_module:17:47 { code: 'ERR_ACCESS_DENIED', permission: 'WorkerThreads' diff --git a/lib/fs.js b/lib/fs.js index 71ccb1d2cec2..cf767b083555 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2025,8 +2025,12 @@ function lstat(path, options = { __proto__: null, bigint: false }, callback) { path = getValidatedPath(path); if (permission.isEnabled() && !permission.has('fs.read', path) && !permission.isAuditMode()) { - const resource = BufferIsBuffer(path) ? BufferToString(path) : path; - callback(new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource)); + const resource = pathModule.toNamespacedPath(BufferIsBuffer(path) ? BufferToString(path) : path); + callback(new ERR_ACCESS_DENIED( + 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', + 'FileSystemRead', + resource, + )); return; } @@ -2150,8 +2154,12 @@ function lstatSync(path, options = { __proto__: null, bigint: false, throwIfNoEn path = getValidatedPath(path); if (permission.isEnabled() && !permission.has('fs.read', path) && !permission.isAuditMode()) { - const resource = BufferIsBuffer(path) ? BufferToString(path) : path; - throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource); + const resource = pathModule.toNamespacedPath(BufferIsBuffer(path) ? BufferToString(path) : path); + throw new ERR_ACCESS_DENIED( + 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', + 'FileSystemRead', + resource, + ); } const stats = binding.lstat( path, diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 53eb2f4938db..66c21e0d5c72 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -1893,7 +1893,11 @@ async function lstat(path, options = { __proto__: null, bigint: false }) { if (permission.isEnabled() && !permission.has('fs.read', path) && !permission.isAuditMode()) { const resource = pathModule.toNamespacedPath(BufferIsBuffer(path) ? BufferToString(path) : path); - throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource); + throw new ERR_ACCESS_DENIED( + 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', + 'FileSystemRead', + resource, + ); } const result = await raceWithSignal( PromisePrototypeThen( diff --git a/test/fixtures/permission/fs-read.js b/test/fixtures/permission/fs-read.js index 1446dd7bc579..07ea619042c3 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -680,39 +680,60 @@ const regularFile = __filename; assert.rejects(async () => { await fsPromises.lstat(blockedFile); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), })).then(common.mustCall()); assert.rejects(async () => { await fsPromises.lstat(blockedFileURL); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), })).then(common.mustCall()); assert.rejects(async () => { await fsPromises.lstat(path.join(blockedFolder, 'anyfile')); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead', + resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), })).then(common.mustCall()); } // fs.lstat { + fs.lstat(blockedFile, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', + code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), + })); assert.throws(() => { fs.lstatSync(blockedFile); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), })); assert.throws(() => { fs.lstatSync(bufferBlockedFile); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), })); assert.throws(() => { fs.lstatSync(path.join(blockedFolder, 'anyfile')); }, common.expectsError({ + message: 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.', code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), })); // doesNotThrow From 8f651d26c8baf685f9454bccba6fa0424447ed64 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 23 Nov 2026 15:00:29 -0300 Subject: [PATCH 2/2] fixup! fs: suggest --allow-fs-read in lstat permission errors test: expect namespaced lstat resource in traversal fixture Assisted-by: Claude Code Signed-off-by: RafaelGSS --- test/fixtures/permission/fs-traversal.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/fixtures/permission/fs-traversal.js b/test/fixtures/permission/fs-traversal.js index d92d3286f75e..91c6b7fc6fee 100644 --- a/test/fixtures/permission/fs-traversal.js +++ b/test/fixtures/permission/fs-traversal.js @@ -73,9 +73,7 @@ const uint8ArrayTraversalPath = new TextEncoder().encode(traversalPath); fs.lstat(bufferTraversalPath, common.expectsError({ code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead', - // lstat checks and throw on JS side. - // resource is only resolved on C++ (is_granted) - resource: bufferTraversalPath.toString(), + resource: path.toNamespacedPath(bufferTraversalPath.toString()), })); }