@@ -100,6 +100,154 @@ If this flag is passed, the behavior can still be set to not abort through
100
100
[ ` process.setUncaughtExceptionCaptureCallback() ` ] [ ] (and through usage of the
101
101
` node:domain ` module that uses it).
102
102
103
+ ### ` --allow-child-process `
104
+
105
+ <!-- YAML
106
+ added: REPLACEME
107
+ -->
108
+
109
+ > Stability: 1 - Experimental
110
+
111
+ When using the [ Permission Model] [ ] , the process will not be able to spawn any
112
+ child process by default.
113
+ Attempts to do so will throw an ` ERR_ACCESS_DENIED ` unless the
114
+ user explicitly passes the ` --allow-child-process ` flag when starting Node.js.
115
+
116
+ Example:
117
+
118
+ ``` js
119
+ const childProcess = require (' node:child_process' );
120
+ // Attempt to bypass the permission
121
+ childProcess .spawn (' node' , [' -e' , ' require("fs").writeFileSync("/new-file", "example")' ]);
122
+ ```
123
+
124
+ ``` console
125
+ $ node --experimental-permission --allow-fs-read=* index.js
126
+ node:internal/child_process:388
127
+ const err = this._handle.spawn(options);
128
+ ^
129
+ Error: Access to this API has been restricted
130
+ at ChildProcess.spawn (node:internal/child_process:388:28)
131
+ at Object.spawn (node:child_process:723:9)
132
+ at Object.<anonymous> (/home/index.js:3:14)
133
+ at Module._compile (node:internal/modules/cjs/loader:1120:14)
134
+ at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
135
+ at Module.load (node:internal/modules/cjs/loader:998:32)
136
+ at Module._load (node:internal/modules/cjs/loader:839:12)
137
+ at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
138
+ at node:internal/main/run_main_module:17:47 {
139
+ code: 'ERR_ACCESS_DENIED',
140
+ permission: 'ChildProcess'
141
+ }
142
+ ```
143
+
144
+ ### ` --allow-fs-read `
145
+
146
+ <!-- YAML
147
+ added: REPLACEME
148
+ -->
149
+
150
+ > Stability: 1 - Experimental
151
+
152
+ This flag configures file system read permissions using
153
+ the [ Permission Model] [ ] .
154
+
155
+ The valid arguments for the ` --allow-fs-read ` flag are:
156
+
157
+ * ` * ` - To allow the ` FileSystemRead ` operations.
158
+ * Paths delimited by comma (,) to manage ` FileSystemRead ` (reading) operations.
159
+
160
+ Examples can be found in the [ File System Permissions] [ ] documentation.
161
+
162
+ Relative paths are NOT yet supported by the CLI flag.
163
+
164
+ The initializer module also needs to be allowed. Consider the following example:
165
+
166
+ ``` console
167
+ $ node --experimental-permission t.js
168
+ node:internal/modules/cjs/loader:162
169
+ const result = internalModuleStat(filename);
170
+ ^
171
+
172
+ Error: Access to this API has been restricted
173
+ at stat (node:internal/modules/cjs/loader:162:18)
174
+ at Module._findPath (node:internal/modules/cjs/loader:640:16)
175
+ at resolveMainPath (node:internal/modules/run_main:15:25)
176
+ at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:53:24)
177
+ at node:internal/main/run_main_module:23:47 {
178
+ code: 'ERR_ACCESS_DENIED',
179
+ permission: 'FileSystemRead',
180
+ resource: '/Users/rafaelgss/repos/os/node/t.js'
181
+ }
182
+ ```
183
+
184
+ The process needs to have access to the ` index.js ` module:
185
+
186
+ ``` console
187
+ $ node --experimental-permission --allow-fs-read=/path/to/index.js index.js
188
+ ```
189
+
190
+ ### ` --allow-fs-write `
191
+
192
+ <!-- YAML
193
+ added: REPLACEME
194
+ -->
195
+
196
+ > Stability: 1 - Experimental
197
+
198
+ This flag configures file system write permissions using
199
+ the [ Permission Model] [ ] .
200
+
201
+ The valid arguments for the ` --allow-fs-write ` flag are:
202
+
203
+ * ` * ` - To allow the ` FileSystemWrite ` operations.
204
+ * Paths delimited by comma (,) to manage ` FileSystemWrite ` (writing) operations.
205
+
206
+ Examples can be found in the [ File System Permissions] [ ] documentation.
207
+
208
+ Relative paths are NOT supported through the CLI flag.
209
+
210
+ ### ` --allow-worker `
211
+
212
+ <!-- YAML
213
+ added: REPLACEME
214
+ -->
215
+
216
+ > Stability: 1 - Experimental
217
+
218
+ When using the [ Permission Model] [ ] , the process will not be able to create any
219
+ worker threads by default.
220
+ For security reasons, the call will throw an ` ERR_ACCESS_DENIED ` unless the
221
+ user explicitly pass the flag ` --allow-worker ` in the main Node.js process.
222
+
223
+ Example:
224
+
225
+ ``` js
226
+ const { Worker } = require (' node:worker_threads' );
227
+ // Attempt to bypass the permission
228
+ new Worker (__filename );
229
+ ```
230
+
231
+ ``` console
232
+ $ node --experimental-permission --allow-fs-read=* index.js
233
+ node:internal/worker:188
234
+ this[kHandle] = new WorkerImpl(url,
235
+ ^
236
+
237
+ Error: Access to this API has been restricted
238
+ at new Worker (node:internal/worker:188:21)
239
+ at Object.<anonymous> (/home/index.js.js:3:1)
240
+ at Module._compile (node:internal/modules/cjs/loader:1120:14)
241
+ at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
242
+ at Module.load (node:internal/modules/cjs/loader:998:32)
243
+ at Module._load (node:internal/modules/cjs/loader:839:12)
244
+ at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
245
+ at node:internal/main/run_main_module:17:47 {
246
+ code: 'ERR_ACCESS_DENIED',
247
+ permission: 'WorkerThreads'
248
+ }
249
+ ```
250
+
103
251
### ` --build-snapshot `
104
252
105
253
<!-- YAML
@@ -386,6 +534,20 @@ added:
386
534
387
535
Enable experimental support for the ` https: ` protocol in ` import ` specifiers.
388
536
537
+ ### ` --experimental-permission `
538
+
539
+ <!-- YAML
540
+ added: REPLACEME
541
+ -->
542
+
543
+ Enable the Permission Model for current process. When enabled, the
544
+ following permissions are restricted:
545
+
546
+ * File System - manageable through
547
+ \[ ` --allow-fs-read ` ] \[ ] ,\[ ` allow-fs-write ` ] \[ ] flags
548
+ * Child Process - manageable through \[ ` --allow-child-process ` ] \[ ] flag
549
+ * Worker Threads - manageable through \[ ` --allow-worker ` ] \[ ] flag
550
+
389
551
### ` --experimental-policy `
390
552
391
553
<!-- YAML
@@ -1883,6 +2045,10 @@ Node.js options that are allowed are:
1883
2045
1884
2046
<!-- node-options-node start -->
1885
2047
2048
+ * ` --allow-child-process `
2049
+ * ` --allow-fs-read `
2050
+ * ` --allow-fs-write `
2051
+ * ` --allow-worker `
1886
2052
* ` --conditions ` , ` -C `
1887
2053
* ` --diagnostic-dir `
1888
2054
* ` --disable-proto `
@@ -1896,6 +2062,7 @@ Node.js options that are allowed are:
1896
2062
* ` --experimental-loader `
1897
2063
* ` --experimental-modules `
1898
2064
* ` --experimental-network-imports `
2065
+ * ` --experimental-permission `
1899
2066
* ` --experimental-policy `
1900
2067
* ` --experimental-shadow-realm `
1901
2068
* ` --experimental-specifier-resolution `
@@ -2331,9 +2498,11 @@ done
2331
2498
[ ECMAScript module ] : esm.md#modules-ecmascript-modules
2332
2499
[ ECMAScript module loader ] : esm.md#loaders
2333
2500
[ Fetch API ] : https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
2501
+ [ File System Permissions ] : permissions.md#file-system-permissions
2334
2502
[ Modules loaders ] : packages.md#modules-loaders
2335
2503
[ Node.js issue tracker ] : https://github.com/nodejs/node/issues
2336
2504
[ OSSL_PROVIDER-legacy ] : https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html
2505
+ [ Permission Model ] : permissions.md#permission-model
2337
2506
[ REPL ] : repl.md
2338
2507
[ ScriptCoverage ] : https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage
2339
2508
[ ShadowRealm ] : https://github.com/tc39/proposal-shadowrealm
0 commit comments