Skip to content

Commit 5e4da4d

Browse files
committed
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: nodejs#59818 Signed-off-by: David Evans <[email protected]>
1 parent db3a8d8 commit 5e4da4d

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

‎lib/internal/process/pre_execution.js‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -682,20 +682,18 @@ function initializePermission() {
682682
ObjectFreeze(require('path'));
683683
const { has, drop } = require('internal/process/permission');
684684
const warnFlags = [
685-
'--allow-addons',
686-
'--allow-child-process',
687-
'--allow-inspector',
688-
'--allow-wasi',
689-
'--allow-worker',
685+
{ flag: '--allow-addons', enabled: true, code: 'PERM0001' },
686+
{ flag: '--allow-child-process', enabled: true, code: 'PERM0002' },
687+
{ flag: '--allow-ffi', enabled: process.config.variables.node_use_ffi, code: 'PERM0003' },
688+
{ flag: '--allow-inspector', enabled: true, code: 'PERM0004' },
689+
{ flag: '--allow-wasi', enabled: true, code: 'PERM0005' },
690+
{ flag: '--allow-worker', enabled: true, code: 'PERM0006' },
690691
];
691-
if (process.config.variables.node_use_ffi) {
692-
warnFlags.splice(2, 0, '--allow-ffi');
693-
}
694-
for (const flag of warnFlags) {
695-
if (getOptionValue(flag)) {
692+
for (const { flag, enabled, code } of warnFlags) {
693+
if (enabled && getOptionValue(flag)) {
696694
process.emitWarning(
697695
`The flag ${flag} must be used with extreme caution. ` +
698-
'It could invalidate the permission model.', 'SecurityWarning');
696+
'It could invalidate the permission model.', 'SecurityWarning', code);
699697
}
700698
}
701699
const warnCommaFlags = [

‎test/parallel/test-permission-warning-flags.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ for (const flag of warnFlags) {
2525
]
2626
);
2727

28-
assert.match(stderr.toString(), new RegExp(`SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
28+
assert.match(stderr.toString(), new RegExp(`\\[PERM\\d{4}\\] SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
2929
assert.strictEqual(status, 0);
3030
}

0 commit comments

Comments
 (0)