GeezerVison is showing github.com — permission: add unique warning codes · nodejs/node@eb61b7e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js +9-11Lines changed: 9 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -681,20 +681,18 @@ function initializePermission() { | 681 | 681 | ObjectFreeze(require('path')); | 682 | 682 | const { has, drop } = require('internal/process/permission'); | 683 | 683 | const warnFlags = [ | 684 | | - '--allow-addons', | 685 | | - '--allow-child-process', | 686 | | - '--allow-inspector', | 687 | | - '--allow-wasi', | 688 | | - '--allow-worker', | | 684 | + { flag: '--allow-addons', enabled: true, code: 'PERM0001' }, | | 685 | + { flag: '--allow-child-process', enabled: true, code: 'PERM0002' }, | | 686 | + { flag: '--allow-ffi', enabled: process.config.variables.node_use_ffi, code: 'PERM0003' }, | | 687 | + { flag: '--allow-inspector', enabled: true, code: 'PERM0004' }, | | 688 | + { flag: '--allow-wasi', enabled: true, code: 'PERM0005' }, | | 689 | + { flag: '--allow-worker', enabled: true, code: 'PERM0006' }, | 689 | 690 | ]; | 690 | | - if (process.config.variables.node_use_ffi) { | 691 | | - warnFlags.splice(2, 0, '--allow-ffi'); | 692 | | - } | 693 | | - for (const flag of warnFlags) { | 694 | | - if (getOptionValue(flag)) { | | 691 | + for (const { flag, enabled, code } of warnFlags) { | | 692 | + if (enabled && getOptionValue(flag)) { | 695 | 693 | process.emitWarning( | 696 | 694 | `The flag ${flag} must be used with extreme caution. ` + | 697 | | - 'It could invalidate the permission model.', 'SecurityWarning'); | | 695 | + 'It could invalidate the permission model.', 'SecurityWarning', code); | 698 | 696 | } | 699 | 697 | } | 700 | 698 | const warnCommaFlags = [ | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-permission-warning-flags.js +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,20 @@ for (const flag of warnFlags) { | 25 | 25 | ] | 26 | 26 | ); | 27 | 27 |
| 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`)); | 29 | 29 | assert.strictEqual(status, 0); | 30 | 30 | } | | 31 | + | | 32 | +const { status, stderr } = spawnSync( | | 33 | + process.execPath, | | 34 | + [ | | 35 | + '--permission', '--allow-child-process', '--allow-wasi', '--disable-warning=PERM0002', '-e', | | 36 | + 'setTimeout(() => {}, 1)', | | 37 | + ] | | 38 | +); | | 39 | + | | 40 | +// Disabled warning does not appear | | 41 | +assert.doesNotMatch(stderr.toString(), new RegExp(`The flag --allow-child-process must be used with extreme caution`)); | | 42 | +// But non-disabled warnings still appear | | 43 | +assert.match(stderr.toString(), new RegExp(`The flag --allow-wasi must be used with extreme caution`)); | | 44 | +assert.strictEqual(status, 0); |
|