| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -549,7 +549,8 @@ function getPermissionModelFlagsToCopy() { | |||
| 549 | 549 | ||
| 550 | 550 | function copyPermissionModelFlagsToEnv(env, key, args) { | |
| 551 | 551 | // Do not override if permission was already passed to file | |
| 552 | - if (args.includes('--permission') || (env[key] && env[key].indexOf('--permission') !== -1)) { | ||
| 552 | + if (args.includes('--permission') || args.includes('--permission-audit') || | ||
| 553 | + (env[key] && env[key].indexOf('--permission') !== -1)) { | ||
| 553 | 554 | return; | |
| 554 | 555 | } | |
| 555 | 556 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,11 @@ DynamicLibrary.prototype[SymbolDispose] = function() { | |||
| 61 | 61 | }; | |
| 62 | 62 | ||
| 63 | 63 | function checkFFIPermission() { | |
| 64 | - if (!permission.isEnabled() || permission.has('ffi')) { | ||
| 64 | + if (!permission.isEnabled()) { | ||
| 65 | + return; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (permission.has('ffi') || permission.isAuditMode()) { | ||
| 65 | 69 | return; | |
| 66 | 70 | } | |
| 67 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,17 +11,25 @@ const { Buffer } = require('buffer'); | |||
| 11 | 11 | const { isBuffer } = Buffer; | |
| 12 | 12 | ||
| 13 | 13 | let _permission; | |
| 14 | + let _audit; | ||
| 14 | 15 | let _ffi; | |
| 15 | 16 | ||
| 16 | 17 | module.exports = ObjectFreeze({ | |
| 17 | 18 | __proto__: null, | |
| 18 | 19 | isEnabled() { | |
| 19 | 20 | if (_permission === undefined) { | |
| 20 | 21 | const { getOptionValue } = require('internal/options'); | |
| 21 | - _permission = getOptionValue('--permission'); | ||
| 22 | + _permission = getOptionValue('--permission') || getOptionValue('--permission-audit'); | ||
| 22 | 23 | } | |
| 23 | 24 | return _permission; | |
| 24 | 25 | }, | |
| 26 | + isAuditMode() { | ||
| 27 | + if (_audit === undefined) { | ||
| 28 | + const { getOptionValue } = require('internal/options'); | ||
| 29 | + _audit = getOptionValue('--permission-audit'); | ||
| 30 | + } | ||
| 31 | + return _audit; | ||
| 32 | + }, | ||
| 25 | 33 | has(scope, reference) { | |
| 26 | 34 | validateString(scope, 'scope'); | |
| 27 | 35 | if (reference != null) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,93 @@ | |||
| 1 | + // Flags: --permission-audit --allow-child-process --allow-fs-read=* --allow-fs-write=* | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const { isMainThread } = require('worker_threads'); | ||
| 6 | + | ||
| 7 | + if (!isMainThread) { | ||
| 8 | + common.skip('This test only works on a main thread'); | ||
| 9 | + } | ||
| 10 | + if (process.config.variables.node_without_node_options) { | ||
| 11 | + common.skip('missing NODE_OPTIONS support'); | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + const assert = require('assert'); | ||
| 15 | + const childProcess = require('child_process'); | ||
| 16 | + | ||
| 17 | + // Verify that the parent is running in audit mode | ||
| 18 | + assert.strictEqual(typeof process.permission.has, 'function'); | ||
| 19 | + | ||
| 20 | + { | ||
| 21 | + assert.strictEqual(process.env.NODE_OPTIONS, undefined); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + // Child should inherit --permission-audit and the allow-flags via NODE_OPTIONS | ||
| 25 | + { | ||
| 26 | + const { status, stdout } = childProcess.spawnSync(process.execPath, | ||
| 27 | + [ | ||
| 28 | + '-e', | ||
| 29 | + ` | ||
| 30 | + console.log(typeof process.permission); | ||
| 31 | + console.log(process.permission.has("fs.write")); | ||
| 32 | + console.log(process.permission.has("fs.read")); | ||
| 33 | + console.log(process.permission.has("child")); | ||
| 34 | + `, | ||
| 35 | + ] | ||
| 36 | + ); | ||
| 37 | + assert.strictEqual(status, 0); | ||
| 38 | + const [permType, fsWrite, fsRead, child] = stdout.toString().split('\n'); | ||
| 39 | + assert.strictEqual(permType, 'object'); | ||
| 40 | + assert.strictEqual(fsWrite, 'true'); | ||
| 41 | + assert.strictEqual(fsRead, 'true'); | ||
| 42 | + assert.strictEqual(child, 'true'); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + // Child spawned with explicit --permission should use its own flags, not inherit parent's | ||
| 46 | + { | ||
| 47 | + const { status, stdout } = childProcess.spawnSync( | ||
| 48 | + process.execPath, | ||
| 49 | + [ | ||
| 50 | + '--permission', | ||
| 51 | + '--allow-fs-write=*', | ||
| 52 | + '-e', | ||
| 53 | + ` | ||
| 54 | + console.log(typeof process.permission); | ||
| 55 | + console.log(process.permission.has("fs.write")); | ||
| 56 | + console.log(process.permission.has("fs.read")); | ||
| 57 | + console.log(process.permission.has("child")); | ||
| 58 | + `, | ||
| 59 | + ] | ||
| 60 | + ); | ||
| 61 | + assert.strictEqual(status, 0); | ||
| 62 | + const [permType, fsWrite, fsRead, child] = stdout.toString().split('\n'); | ||
| 63 | + assert.strictEqual(permType, 'object'); | ||
| 64 | + assert.strictEqual(fsWrite, 'true'); | ||
| 65 | + assert.strictEqual(fsRead, 'false'); | ||
| 66 | + assert.strictEqual(child, 'false'); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + // Child spawned with explicit --permission-audit should use its own flags | ||
| 70 | + { | ||
| 71 | + const { status, stdout } = childProcess.spawnSync( | ||
| 72 | + process.execPath, | ||
| 73 | + [ | ||
| 74 | + '--permission-audit', | ||
| 75 | + '--allow-fs-write=*', | ||
| 76 | + '-e', | ||
| 77 | + ` | ||
| 78 | + console.log(typeof process.permission); | ||
| 79 | + console.log(process.permission.has("fs.write")); | ||
| 80 | + console.log(process.permission.has("fs.read")); | ||
| 81 | + `, | ||
| 82 | + ] | ||
| 83 | + ); | ||
| 84 | + assert.strictEqual(status, 0); | ||
| 85 | + const [permType, fsWrite, fsRead] = stdout.toString().split('\n'); | ||
| 86 | + assert.strictEqual(permType, 'object'); | ||
| 87 | + assert.strictEqual(fsWrite, 'true'); | ||
| 88 | + assert.strictEqual(fsRead, 'false'); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + { | ||
| 92 | + assert.strictEqual(process.env.NODE_OPTIONS, undefined); | ||
| 93 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments