Skip to content

Commit 8f4325d

Browse files
committed
permission: fix wildcard when children > 1
PR-URL: #51209 Fixes: #50659 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent ec6fcff commit 8f4325d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/permission/fs_permission.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ class FSPermission final : public PermissionBase {
7878
return nullptr;
7979
}
8080

81+
// wildcard node takes precedence
82+
if (children.size() > 1) {
83+
auto it = children.find('*');
84+
if (it != children.end()) {
85+
return it->second;
86+
}
87+
}
88+
8189
auto it = children.find(path[idx]);
8290
if (it == children.end()) {
8391
return nullptr;

test/parallel/test-permission-fs-wildcard.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,23 @@ if (common.isWindows) {
9898
);
9999
assert.strictEqual(status, 0, stderr.toString());
100100
}
101+
102+
{
103+
if (!common.isWindows) {
104+
const { status, stderr } = spawnSync(
105+
process.execPath,
106+
[
107+
'--experimental-permission',
108+
'--allow-fs-read=/a/b/*',
109+
'--allow-fs-read=/a/b/d',
110+
'-e',
111+
`
112+
const assert = require('assert')
113+
assert.ok(process.permission.has('fs.read', '/a/b/c'));
114+
assert.ok(!process.permission.has('fs.read', '/a/c/c'));
115+
`,
116+
]
117+
);
118+
assert.strictEqual(status, 0, stderr.toString());
119+
}
120+
}

0 commit comments

Comments
 (0)