node/lib/internal/process/permission.js
Rafael Gonzaga 8173d9d72b
permission: propagate permission model flags on spawn
Previously, only child_process.fork propagated the exec
arguments (execvArgs) to the child process.
This commit adds support for spawn and spawnSync to
propagate permission model flags — except when they are
already provided explicitly via arguments or through
NODE_OPTIONS.

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/58853
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2025-07-02 02:32:20 +00:00

47 lines
1.1 KiB
JavaScript

'use strict';
const {
ObjectFreeze,
} = primordials;
const permission = internalBinding('permission');
const { validateString, validateBuffer } = require('internal/validators');
const { Buffer } = require('buffer');
const { isBuffer } = Buffer;
let _permission;
module.exports = ObjectFreeze({
__proto__: null,
isEnabled() {
if (_permission === undefined) {
const { getOptionValue } = require('internal/options');
_permission = getOptionValue('--permission');
}
return _permission;
},
has(scope, reference) {
validateString(scope, 'scope');
if (reference != null) {
// TODO: add support for WHATWG URLs and Uint8Arrays.
if (isBuffer(reference)) {
validateBuffer(reference, 'reference');
} else {
validateString(reference, 'reference');
}
}
return permission.has(scope, reference);
},
availableFlags() {
return [
'--allow-fs-read',
'--allow-fs-write',
'--allow-addons',
'--allow-child-process',
'--allow-net',
'--allow-wasi',
'--allow-worker',
];
},
});