Skip to content

Commit 995de8e

Browse files
committed
fixup! lib,permission: add permission.drop
1 parent 629d86a commit 995de8e

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

doc/api/permissions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ API call to drop permissions at runtime. This operation is **irreversible**.
9898

9999
When called without a reference, the entire scope is dropped. When called
100100
with a reference, only the permission for that specific resource is revoked.
101+
Dropping a permission only affects future access checks. It does not close or
102+
revoke access to resources that are already open, such as file descriptors,
103+
network sockets, child processes, or worker threads. Applications are
104+
responsible for closing or terminating those resources when they are no longer
105+
needed.
101106

102107
You can only drop the exact resource that was explicitly granted. The
103108
reference passed to `drop()` must match the original grant. If a permission

src/permission/ffi_permission.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ void FFIPermission::Apply(Environment* env,
1414
deny_all_ = true;
1515
}
1616

17+
void FFIPermission::Drop(Environment* env,
18+
PermissionScope scope,
19+
const std::string_view& param) {
20+
deny_all_ = true;
21+
}
22+
1723
bool FFIPermission::is_granted(Environment* env,
1824
PermissionScope perm,
1925
const std::string_view& param) const {

src/permission/ffi_permission.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class FFIPermission final : public PermissionBase {
1515
void Apply(Environment* env,
1616
const std::vector<std::string>& allow,
1717
PermissionScope scope) override;
18+
void Drop(Environment* env,
19+
PermissionScope scope,
20+
const std::string_view& param = "") override;
1821
bool is_granted(Environment* env,
1922
PermissionScope perm,
2023
const std::string_view& param = "") const override;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Flags: --permission --allow-ffi --allow-fs-read=*
2+
'use strict';
3+
4+
const common = require('../common');
5+
const { fixtureSymbols, libraryPath } = require('./ffi-test-common');
6+
7+
common.skipIfFFIMissing();
8+
9+
const ffi = require('node:ffi');
10+
const assert = require('assert');
11+
12+
function openLibrary() {
13+
const { lib } = ffi.dlopen(libraryPath, {
14+
add_i32: fixtureSymbols.add_i32,
15+
allocate_memory: fixtureSymbols.allocate_memory,
16+
deallocate_memory: fixtureSymbols.deallocate_memory,
17+
});
18+
lib.close();
19+
}
20+
21+
22+
{
23+
assert.ok(process.permission.has('ffi'));
24+
}
25+
26+
{
27+
// shouldNotThrow
28+
openLibrary();
29+
}
30+
31+
{
32+
process.permission.drop('ffi');
33+
assert.ok(!process.permission.has('ffi'));
34+
assert.throws(() => {
35+
openLibrary();
36+
}, common.expectsError({
37+
code: 'ERR_ACCESS_DENIED',
38+
permission: 'FFI',
39+
}));
40+
}

0 commit comments

Comments
 (0)