Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 90e12f2

Browse filesBrowse files
RafaelGSSaduh95
authored andcommitted
test: clarify fork inherit permission flags
This commit updates the documentation and includes a test to ensure that permission model flags will be passed to the child process if `fork` is called PR-URL: #56523 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 334a3ac commit 90e12f2
Copy full SHA for 90e12f2

File tree

Expand file treeCollapse file tree

2 files changed

+15
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-8
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+6-7Lines changed: 6 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,18 @@ node:internal/child_process:388
174174
^
175175
Error: Access to this API has been restricted
176176
at ChildProcess.spawn (node:internal/child_process:388:28)
177-
at Object.spawn (node:child_process:723:9)
178-
at Object.<anonymous> (/home/index.js:3:14)
179-
at Module._compile (node:internal/modules/cjs/loader:1120:14)
180-
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
181-
at Module.load (node:internal/modules/cjs/loader:998:32)
182-
at Module._load (node:internal/modules/cjs/loader:839:12)
183-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
184177
at node:internal/main/run_main_module:17:47 {
185178
code: 'ERR_ACCESS_DENIED',
186179
permission: 'ChildProcess'
187180
}
188181
```
189182

183+
Unlike `child_process.spawn`, the `child_process.fork` API copies the execution
184+
arguments from the parent process. This means that if you start Node.js with the
185+
Permission Model enabled and include the `--allow-child-process` flag, calling
186+
`child_process.fork()` will propagate all Permission Model flags to the child
187+
process.
188+
190189
### `--allow-fs-read`
191190

192191
<!-- YAML
Collapse file

‎test/parallel/test-permission-allow-child-process-cli.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-permission-allow-child-process-cli.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ const common = require('../common');
55
common.skipIfWorker();
66
const assert = require('assert');
77
const childProcess = require('child_process');
8+
const fs = require('fs');
89

910
if (process.argv[2] === 'child') {
11+
assert.throws(() => {
12+
fs.writeFileSync(__filename, 'should not write');
13+
}, common.expectsError({
14+
code: 'ERR_ACCESS_DENIED',
15+
permission: 'FileSystemWrite',
16+
}));
1017
process.exit(0);
1118
}
1219

@@ -21,6 +28,7 @@ if (process.argv[2] === 'child') {
2128
// doesNotThrow
2229
childProcess.spawnSync(process.execPath, ['--version']);
2330
childProcess.execSync(...common.escapePOSIXShell`"${process.execPath}" --version`);
24-
childProcess.fork(__filename, ['child']);
31+
const child = childProcess.fork(__filename, ['child']);
32+
child.on('close', common.mustCall());
2533
childProcess.execFileSync(process.execPath, ['--version']);
2634
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.