Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: clarify fork inherit permission flags #56523

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,18 @@ node:internal/child_process:388
^
Error: Access to this API has been restricted
at ChildProcess.spawn (node:internal/child_process:388:28)
at Object.spawn (node:child_process:723:9)
at Object.<anonymous> (/home/index.js:3:14)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'ChildProcess'
}
```

Unlike `child_process.spawn`, the `child_process.fork` API copies the execution
arguments from the parent process. This means that if you start Node.js with the
Permission Model enabled and include the `--allow-child-process` flag, calling
`child_process.fork()` will propagate all Permission Model flags to the child
process.

### `--allow-fs-read`

<!-- YAML
Expand Down
10 changes: 9 additions & 1 deletion test/parallel/test-permission-allow-child-process-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ const common = require('../common');
common.skipIfWorker();
const assert = require('assert');
const childProcess = require('child_process');
const fs = require('fs');

if (process.argv[2] === 'child') {
assert.throws(() => {
fs.writeFileSync(__filename, 'should not write');
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
}));
process.exit(0);
}

Expand All @@ -21,6 +28,7 @@ if (process.argv[2] === 'child') {
// doesNotThrow
childProcess.spawnSync(process.execPath, ['--version']);
childProcess.execSync(...common.escapePOSIXShell`"${process.execPath}" --version`);
childProcess.fork(__filename, ['child']);
const child = childProcess.fork(__filename, ['child']);
child.on('close', common.mustCall());
childProcess.execFileSync(process.execPath, ['--version']);
}
Loading