Repository navigation
Description
Version
v26.12.1
Platform
Microsoft Windows NT 10.0.26100.0 x64
Subsystem
permission
What steps will reproduce the bug?
On Windows, with a reachable SMB share \\server\share containing data.txt:
- Create a local script
C:\test\test.js:
const fs = require('fs');
const dir = process.argv[2];
console.log(fs.readFileSync(dir + '\\data.txt', 'utf8'));
fs.writeFileSync(dir + '\\written.txt', 'ok');
console.log('write ok');- Run it with the share granted:
node --permission --allow-fs-read=C:\test --allow-fs-read=\\server\share --allow-fs-write=\\server\share C:\test\test.js \\server\share
The same ERR_ACCESS_DENIED happens with every grant form tried:
\\server\share\\server\share\*\\?\UNC\server\share\\?\UNC\server\share\*- short and long forms granted together
It also happens when the entry script itself is on the share (node --permission --allow-fs-read=\\server\share \\server\share\test.js), and when the share is reached through a directory symlink (mklink /D C:\link \\server\share, granting C:\link).
How often does it reproduce? Is there a required condition?
Always, whenever the accessed path is on a network share (UNC). Tested on v26.12.1, v24.22.1 and v24.15.0.
The same share mapped to a drive letter (New-SmbGlobalMapping -LocalPath Y:) with --allow-fs-read=Y:\ works on all three versions. --allow-fs-read=* also works.
What is the expected behavior? Why is that the expected behavior?
An explicitly granted UNC path should be readable/writable, the same as a granted local path. Today a network share can only be used with --allow-fs-read=* / --allow-fs-write=*, which turns the file-system permission model off entirely.
What do you see instead?
Error: Access to this API has been restricted. Use --allow-fs-read to manage permissions.
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: '\\\\?\\UNC\\server\\share\\data.txt'
Additional information
The two sides of the check are converted differently in src/permission/fs_permission.cc (same code in v24.22.1, v26.12.1 and main):
- is_tree_granted() strips a leading "\?" and then "UNC" from the path being checked, so
\\?\UNC\server\share\data.txtis looked up asserver\share\data.txt(added in 2524d00, CVE-2024-37372). - Apply()/GrantAccess() only apply PathResolve + WildcardIfDir, so the grant is stored as
\\server\share\*(or\\?\UNC\server\share\*).
server\share\... never matches \\server\share\..., so no UNC grant can ever be honoured. A grant without the leading \\ doesn't help either, because PathResolve treats it as relative to the current directory.
The test added in 2524d00 only checks that an ungranted UNC path is denied. Nothing tests that a granted UNC path is allowed.
Possible fix: apply the same conversion to grants (strip "\?", "UNC" and a leading "\") after WildcardIfDir, using one helper shared by GrantAccess and is_tree_granted, and add a test with a granted UNC path. I'm happy to open a PR if this approach is acceptable.
Activity