src: fix the fs permission tree node on wildcard nodes

Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/986
Fixes: https://hackerone.com/reports/3996423
CVE-ID: CVE-2026-106071
This commit is contained in:
James M Snell authored and Antoine du Hamel committed 2026-10-21 12:57:43 +02:00
1 parent c5f5cb5b96
commit 5faa1497e0
2 files changed
+33 -2

No files matched your search

+2 -2
View File
@@ -129,8 +129,8 @@ class FSPermission final : public PermissionBase {
}
// match prefix
size_t prefix_len = child->prefix.length();
for (size_t i = 0; i < path.length(); ++i) {
if (i >= prefix_len || child->prefix[i] == '*') {
for (size_t i = 0; i < prefix_len; ++i) {
if (child->prefix[i] == '*') {
return child;
}
@@ -126,3 +126,34 @@ if (common.isWindows) {
assert.strictEqual(status, 0, stderr.toString());
}
}
{
// Each scope holds a single grant, so its wildcard node sits directly under
// the radix tree root. Removing the `*` and the character before it must not
// produce a granted path.
if (!common.isWindows) {
const { status, stderr } = spawnSync(
process.execPath,
[
'--permission',
'--allow-fs-read=/tmp/test*',
'--allow-fs-write=/tmp/test/*',
'-e',
`
const assert = require('assert');
assert.ok(process.permission.has('fs.read', '/tmp/test'));
assert.ok(process.permission.has('fs.read', '/tmp/test2'));
assert.ok(process.permission.has('fs.read', '/tmp/test/file'));
assert.ok(!process.permission.has('fs.read', '/tmp/tes'));
assert.ok(!process.permission.has('fs.read', '/tmp/te'));
assert.ok(process.permission.has('fs.write', '/tmp/test'));
assert.ok(process.permission.has('fs.write', '/tmp/test/'));
assert.ok(process.permission.has('fs.write', '/tmp/test/file'));
assert.ok(!process.permission.has('fs.write', '/tmp/tes'));
assert.ok(!process.permission.has('fs.write', '/tmp/test2'));
`,
]
);
assert.strictEqual(status, 0, stderr.toString());
}
}