Skip to content

Commit 3d2d0fa

Browse files
committed
permission: enforce addon permission in GetLinkedBinding
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent e7904d4 commit 3d2d0fa

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/node_binding.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
672672

673673
node::Utf8Value module_name_v(env->isolate(), module_name);
674674
const char* name = *module_name_v;
675+
THROW_IF_INSUFFICIENT_PERMISSIONS(
676+
env, permission::PermissionScope::kAddon, module_name_v.ToStringView());
677+
675678
node_module* mod = nullptr;
676679

677680
// Iterate from here to the nearest non-Worker Environment to see if there's
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Flags: --permission --allow-addons --allow-fs-read=*
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('node:assert');
6+
7+
assert.strictEqual(process.permission.has('addon'), true);
8+
9+
process.permission.drop('addon');
10+
11+
assert.strictEqual(process.permission.has('addon'), false);
12+
13+
assert.throws(() => {
14+
process._linkedBinding('missing');
15+
}, common.expectsError({
16+
code: 'ERR_ACCESS_DENIED',
17+
permission: 'Addon',
18+
resource: 'missing',
19+
}));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Flags: --permission --allow-fs-read=*
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('node:assert');
6+
7+
assert.strictEqual(process.permission.has('addon'), false);
8+
9+
assert.throws(() => {
10+
process._linkedBinding('missing');
11+
}, common.expectsError({
12+
code: 'ERR_ACCESS_DENIED',
13+
permission: 'Addon',
14+
resource: 'missing',
15+
}));

0 commit comments

Comments
 (0)