Skip to content

Commit 980c651

Browse files
davidje13aduh95
authored andcommitted
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: #59818 Signed-off-by: David Evans <davidje13@users.noreply.github.com> PR-URL: #64414 Backport-PR-URL: #65354 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 30ae8ab commit 980c651

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

lib/internal/process/pre_execution.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,17 +643,17 @@ function initializePermission() {
643643
ObjectFreeze(require('path'));
644644
const { has, drop } = require('internal/process/permission');
645645
const warnFlags = [
646-
'--allow-addons',
647-
'--allow-child-process',
648-
'--allow-inspector',
649-
'--allow-wasi',
650-
'--allow-worker',
646+
{ flag: '--allow-addons', enabled: true, code: 'PERM0001' },
647+
{ flag: '--allow-child-process', enabled: true, code: 'PERM0002' },
648+
{ flag: '--allow-inspector', enabled: true, code: 'PERM0004' },
649+
{ flag: '--allow-wasi', enabled: true, code: 'PERM0005' },
650+
{ flag: '--allow-worker', enabled: true, code: 'PERM0006' },
651651
];
652-
for (const flag of warnFlags) {
653-
if (getOptionValue(flag)) {
652+
for (const { flag, enabled, code } of warnFlags) {
653+
if (enabled && getOptionValue(flag)) {
654654
process.emitWarning(
655655
`The flag ${flag} must be used with extreme caution. ` +
656-
'It could invalidate the permission model.', 'SecurityWarning');
656+
'It could invalidate the permission model.', 'SecurityWarning', code);
657657
}
658658
}
659659
const warnCommaFlags = [

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ for (const flag of warnFlags) {
2121
]
2222
);
2323

24-
assert.match(stderr.toString(), new RegExp(`SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
24+
assert.match(stderr.toString(), new RegExp(`\\[PERM\\d{4}\\] SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
2525
assert.strictEqual(status, 0);
2626
}
27+
28+
const { status, stderr } = spawnSync(
29+
process.execPath,
30+
[
31+
'--permission', '--allow-child-process', '--allow-wasi', '--disable-warning=PERM0002', '-e',
32+
'setTimeout(() => {}, 1)',
33+
]
34+
);
35+
36+
// Disabled warning does not appear
37+
assert.doesNotMatch(stderr.toString(), new RegExp(`The flag --allow-child-process must be used with extreme caution`));
38+
// But non-disabled warnings still appear
39+
assert.match(stderr.toString(), new RegExp(`The flag --allow-wasi must be used with extreme caution`));
40+
assert.strictEqual(status, 0);

0 commit comments

Comments
 (0)