Skip to content

Commit 90e12f2

Browse 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

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

doc/api/cli.md

Lines changed: 6 additions & 7 deletions
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

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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy