From 92a3dc3191c083bbcf98d70dca828d1929112508 Mon Sep 17 00:00:00 2001 From: Martin Wagner Date: Thu, 2 Jul 2026 17:28:24 +0200 Subject: [PATCH] lib,permission: fix addon permission drop Signed-off-by: Martin PR-URL: https://github.com/nodejs/node/pull/64007 Reviewed-By: Rafael Gonzaga Reviewed-By: Edy Silva --- src/node_binding.cc | 3 ++ test/parallel/test-permission-drop-addons.js | 38 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/parallel/test-permission-drop-addons.js diff --git a/src/node_binding.cc b/src/node_binding.cc index db90d76853a..2286af2e3c4 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -5,6 +5,7 @@ #include "node_errors.h" #include "node_external_reference.h" #include "node_url_pattern.h" +#include "permission/permission.h" #include "util.h" #include @@ -449,6 +450,8 @@ void DLOpen(const FunctionCallbackInfo& args) { return THROW_ERR_DLOPEN_DISABLED( env, "Cannot load native addon because loading addons is disabled."); } + THROW_IF_INSUFFICIENT_PERMISSIONS( + env, permission::PermissionScope::kAddon, ""); auto context = env->context(); diff --git a/test/parallel/test-permission-drop-addons.js b/test/parallel/test-permission-drop-addons.js new file mode 100644 index 00000000000..baf87c3b95b --- /dev/null +++ b/test/parallel/test-permission-drop-addons.js @@ -0,0 +1,38 @@ +// Flags: --permission --allow-addons --allow-fs-read=* +'use strict'; + +const common = require('../common'); +const { isMainThread } = require('worker_threads'); + +if (!isMainThread) { + common.skip('This test only works on a main thread'); +} + +const assert = require('assert'); + +let bindingPath; +try { + bindingPath = require.resolve( + `../addons/hello-world/build/${common.buildType}/binding`); +} catch (err) { + if (err.code !== 'MODULE_NOT_FOUND') { + throw err; + } + common.skip('addon not found'); +} + +function openAddon() { + process.dlopen({ exports: {} }, bindingPath); +} + +assert.ok(process.permission.has('addon')); +openAddon(); + +process.permission.drop('addon'); +assert.ok(!process.permission.has('addon')); +assert.throws(() => { + openAddon(); +}, common.expectsError({ + code: 'ERR_ACCESS_DENIED', + permission: 'Addon', +}));