permission: add unique warning codes

Adds unique warning codes of the form PERM0000 for all permissions
related SecurityWarnings, so that they can be individually silenced
if required.

Fixes: https://github.com/nodejs/node/issues/59818
Signed-off-by: David Evans <davidje13@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/64414
Backport-PR-URL: https://github.com/nodejs/node/pull/65354
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
David Evans authored and Antoine du Hamel committed 2026-08-20 14:01:04 +02:00
1 parent 30ae8ab091
commit 980c651de5
2 files changed
+23 -9

No files matched your search

+8 -8
View File
@@ -643,17 +643,17 @@ function initializePermission() {
ObjectFreeze(require('path'));
const { has, drop } = require('internal/process/permission');
const warnFlags = [
'--allow-addons',
'--allow-child-process',
'--allow-inspector',
'--allow-wasi',
'--allow-worker',
{ flag: '--allow-addons', enabled: true, code: 'PERM0001' },
{ flag: '--allow-child-process', enabled: true, code: 'PERM0002' },
{ flag: '--allow-inspector', enabled: true, code: 'PERM0004' },
{ flag: '--allow-wasi', enabled: true, code: 'PERM0005' },
{ flag: '--allow-worker', enabled: true, code: 'PERM0006' },
];
for (const flag of warnFlags) {
if (getOptionValue(flag)) {
for (const { flag, enabled, code } of warnFlags) {
if (enabled && getOptionValue(flag)) {
process.emitWarning(
`The flag ${flag} must be used with extreme caution. ` +
'It could invalidate the permission model.', 'SecurityWarning');
'It could invalidate the permission model.', 'SecurityWarning', code);
}
}
const warnCommaFlags = [
+15 -1
View File
@@ -21,6 +21,20 @@ for (const flag of warnFlags) {
]
);
assert.match(stderr.toString(), new RegExp(`SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
assert.match(stderr.toString(), new RegExp(`\\[PERM\\d{4}\\] SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
assert.strictEqual(status, 0);
}
const { status, stderr } = spawnSync(
process.execPath,
[
'--permission', '--allow-child-process', '--allow-wasi', '--disable-warning=PERM0002', '-e',
'setTimeout(() => {}, 1)',
]
);
// Disabled warning does not appear
assert.doesNotMatch(stderr.toString(), new RegExp(`The flag --allow-child-process must be used with extreme caution`));
// But non-disabled warnings still appear
assert.match(stderr.toString(), new RegExp(`The flag --allow-wasi must be used with extreme caution`));
assert.strictEqual(status, 0);