mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
8d3ae0830e
commit
eb61b7ee1e
2 files changed
+24
-12
No files matched your search
@@ -681,20 +681,18 @@ 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-ffi', enabled: process.config.variables.node_use_ffi, code: 'PERM0003' },
|
||||
{ flag: '--allow-inspector', enabled: true, code: 'PERM0004' },
|
||||
{ flag: '--allow-wasi', enabled: true, code: 'PERM0005' },
|
||||
{ flag: '--allow-worker', enabled: true, code: 'PERM0006' },
|
||||
];
|
||||
if (process.config.variables.node_use_ffi) {
|
||||
warnFlags.splice(2, 0, '--allow-ffi');
|
||||
}
|
||||
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 = [
|
||||
|
||||
@@ -25,6 +25,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);
|
||||
Reference in new issue
Block a user