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 <admin@stephenbelanger.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
RafaelGSS committed Jan 2, 2024
1 parent ec6fcff commit 8f4325d
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 8f4325d

Please sign in to comment.