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 Feb 13, 2024
1 parent ed7d149 commit d01dd42
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
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
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 d01dd42

Please sign in to comment.