Skip to content

Commit

Permalink
permission: fix wildcard when children > 1
Browse files Browse the repository at this point in the history
PR-URL: #51209
Fixes: #50659
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
RafaelGSS authored Dec 21, 2023
1 parent b33a1d3 commit 3f2e234
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/permission/fs_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class FSPermission final : public PermissionBase {
return nullptr;
}

// wildcard node takes precedence
if (children.size() > 1) {
auto it = children.find('*');
if (it != children.end()) {
return it->second;
}
}

auto it = children.find(path[idx]);
if (it == children.end()) {
return nullptr;
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-permission-fs-wildcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,23 @@ if (common.isWindows) {
);
assert.strictEqual(status, 0, stderr.toString());
}

{
if (!common.isWindows) {
const { status, stderr } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read=/a/b/*',
'--allow-fs-read=/a/b/d',
'-e',
`
const assert = require('assert')
assert.ok(process.permission.has('fs.read', '/a/b/c'));
assert.ok(!process.permission.has('fs.read', '/a/c/c'));
`,
]
);
assert.strictEqual(status, 0, stderr.toString());
}
}

0 comments on commit 3f2e234

Please sign in to comment.