Skip to content

Commit e1d0505

Browse files
committed
src,lib: stabilize permission model
Move permission model from 1.1 (Active Development) to 2.0 (Stable).
1 parent b17a1fb commit e1d0505

File tree

53 files changed

+121
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+121
-133
lines changed

benchmark/fs/readfile-permission-enabled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, {
1717
concurrent: [1, 10],
1818
}, {
1919
flags: [
20-
'--experimental-permission',
20+
'--permission',
2121
'--allow-fs-read=*',
2222
'--allow-fs-write=*',
2323
'--allow-child-process',

benchmark/permission/permission-processhas-fs-read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const rootPath = path.resolve(__dirname, '../../..');
1111

1212
const options = {
1313
flags: [
14-
'--experimental-permission',
14+
'--permission',
1515
`--allow-fs-read=${rootPath}`,
1616
'--allow-child-process',
1717
'--no-warnings',

benchmark/permission/permission-startup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function spawnProcess(script, bench, state) {
4848
function main({ count, script, nFiles, prefixPath }) {
4949
script = path.resolve(__dirname, '../../', `${script}.js`);
5050
const optionsWithScript = [
51-
'--experimental-permission',
51+
'--permission',
5252
`--allow-fs-read=${script}`,
5353
...mockFiles(nFiles, prefixPath).map((file) => '--allow-fs-read=' + file),
5454
script,

doc/api/cli.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ require('nodejs-addon-example');
126126
```
127127

128128
```console
129-
$ node --experimental-permission --allow-fs-read=* index.js
129+
$ node --permission --allow-fs-read=* index.js
130130
node:internal/modules/cjs/loader:1319
131131
return process.dlopen(module, path.toNamespacedPath(filename));
132132
^
@@ -168,7 +168,7 @@ childProcess.spawn('node', ['-e', 'require("fs").writeFileSync("/new-file", "exa
168168
```
169169

170170
```console
171-
$ node --experimental-permission --allow-fs-read=* index.js
171+
$ node --permission --allow-fs-read=* index.js
172172
node:internal/child_process:388
173173
const err = this._handle.spawn(options);
174174
^
@@ -197,7 +197,7 @@ changes:
197197
description: Paths delimited by comma (`,`) are no longer allowed.
198198
-->
199199

200-
> Stability: 1.1 - Active development
200+
> Stability: 2.0 - Stable.
201201
202202
This flag configures file system read permissions using
203203
the [Permission Model][].
@@ -213,7 +213,7 @@ Examples can be found in the [File System Permissions][] documentation.
213213
The initializer module also needs to be allowed. Consider the following example:
214214

215215
```console
216-
$ node --experimental-permission index.js
216+
$ node --permission index.js
217217

218218
Error: Access to this API has been restricted
219219
at node:internal/main/run_main_module:23:47 {
@@ -226,7 +226,7 @@ Error: Access to this API has been restricted
226226
The process needs to have access to the `index.js` module:
227227

228228
```bash
229-
node --experimental-permission --allow-fs-read=/path/to/index.js index.js
229+
node --permission --allow-fs-read=/path/to/index.js index.js
230230
```
231231

232232
### `--allow-fs-write`
@@ -239,7 +239,7 @@ changes:
239239
description: Paths delimited by comma (`,`) are no longer allowed.
240240
-->
241241

242-
> Stability: 1.1 - Active development
242+
> Stability: 2.0 - Stable.
243243
244244
This flag configures file system write permissions using
245245
the [Permission Model][].
@@ -285,7 +285,7 @@ new WASI({
285285
```
286286

287287
```console
288-
$ node --experimental-permission --allow-fs-read=* index.js
288+
$ node --permission --allow-fs-read=* index.js
289289

290290
Error: Access to this API has been restricted
291291
at node:internal/main/run_main_module:30:49 {
@@ -316,7 +316,7 @@ new Worker(__filename);
316316
```
317317

318318
```console
319-
$ node --experimental-permission --allow-fs-read=* index.js
319+
$ node --permission --allow-fs-read=* index.js
320320

321321
Error: Access to this API has been restricted
322322
at node:internal/main/run_main_module:17:47 {
@@ -1000,13 +1000,17 @@ added:
10001000
10011001
Enable experimental support for the network inspection with Chrome DevTools.
10021002

1003-
### `--experimental-permission`
1003+
### `--permission`
10041004

10051005
<!-- YAML
10061006
added: v20.0.0
1007+
changes:
1008+
- version: REPLACEME
1009+
pr-url: https://github.com/nodejs/node/pull/56201
1010+
description: Permission Model is now stable.
10071011
-->
10081012

1009-
> Stability: 1.1 - Active development
1013+
> Stability: 2.0 - Stable
10101014
10111015
Enable the Permission Model for current process. When enabled, the
10121016
following permissions are restricted:
@@ -3025,7 +3029,6 @@ one is included in the list below.
30253029
* `--experimental-json-modules`
30263030
* `--experimental-loader`
30273031
* `--experimental-modules`
3028-
* `--experimental-permission`
30293032
* `--experimental-print-required-tla`
30303033
* `--experimental-require-module`
30313034
* `--experimental-shadow-realm`
@@ -3078,6 +3081,7 @@ one is included in the list below.
30783081
* `--openssl-legacy-provider`
30793082
* `--openssl-shared-config`
30803083
* `--pending-deprecation`
3084+
* `--permission`
30813085
* `--preserve-symlinks-main`
30823086
* `--preserve-symlinks`
30833087
* `--prof-process`

doc/api/permissions.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ If you find a potential security vulnerability, please refer to our
2828

2929
<!-- type=misc -->
3030

31-
> Stability: 1.1 - Active development
31+
> Stability: 2.0 - Stable
3232
3333
<!-- name=permission-model -->
3434

3535
The Node.js Permission Model is a mechanism for restricting access to specific
3636
resources during execution.
37-
The API exists behind a flag [`--experimental-permission`][] which when enabled,
37+
The API exists behind a flag [`--permission`][] which when enabled,
3838
will restrict access to all available permissions.
3939

40-
The available permissions are documented by the [`--experimental-permission`][]
40+
The available permissions are documented by the [`--permission`][]
4141
flag.
4242

43-
When starting Node.js with `--experimental-permission`,
43+
When starting Node.js with `--permission`,
4444
the ability to access the file system through the `fs` module, spawn processes,
4545
use `node:worker_threads`, use native addons, use WASI, and enable the runtime inspector
4646
will be restricted.
4747

4848
```console
49-
$ node --experimental-permission index.js
49+
$ node --permission index.js
5050

5151
Error: Access to this API has been restricted
5252
at node:internal/main/run_main_module:23:47 {
@@ -64,7 +64,7 @@ flag. For WASI, use the [`--allow-wasi`][] flag.
6464

6565
#### Runtime API
6666

67-
When enabling the Permission Model through the [`--experimental-permission`][]
67+
When enabling the Permission Model through the [`--permission`][]
6868
flag a new property `permission` is added to the `process` object.
6969
This property contains one function:
7070

@@ -90,10 +90,8 @@ To allow access to the file system, use the [`--allow-fs-read`][] and
9090
[`--allow-fs-write`][] flags:
9191

9292
```console
93-
$ node --experimental-permission --allow-fs-read=* --allow-fs-write=* index.js
93+
$ node --permission --allow-fs-read=* --allow-fs-write=* index.js
9494
Hello world!
95-
(node:19836) ExperimentalWarning: Permission is an experimental feature
96-
(Use `node --trace-warnings ...` to show where the warning was created)
9795
```
9896

9997
The valid arguments for both flags are:
@@ -165,5 +163,5 @@ There are constraints you need to know before using this system:
165163
[`--allow-fs-write`]: cli.md#--allow-fs-write
166164
[`--allow-wasi`]: cli.md#--allow-wasi
167165
[`--allow-worker`]: cli.md#--allow-worker
168-
[`--experimental-permission`]: cli.md#--experimental-permission
166+
[`--permission`]: cli.md#--permission
169167
[`permission.has()`]: process.md#processpermissionhasscope-reference

doc/api/process.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,7 @@ added: v20.0.0
30783078
30793079
* {Object}
30803080
3081-
This API is available through the [`--experimental-permission`][] flag.
3081+
This API is available through the [`--permission`][] flag.
30823082
30833083
`process.permission` is an object whose methods are used to manage permissions
30843084
for the current process. Additional documentation is available in the
@@ -4415,8 +4415,8 @@ cases:
44154415
[`'exit'`]: #event-exit
44164416
[`'message'`]: child_process.md#event-message
44174417
[`'uncaughtException'`]: #event-uncaughtexception
4418-
[`--experimental-permission`]: cli.md#--experimental-permission
44194418
[`--no-deprecation`]: cli.md#--no-deprecation
4419+
[`--permission`]: cli.md#--permission
44204420
[`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
44214421
[`Buffer`]: buffer.md
44224422
[`ChildProcess.disconnect()`]: child_process.md#subprocessdisconnect

doc/node.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ Specify the
176176
.Ar module
177177
to use as a custom module loader.
178178
.
179-
.It Fl -experimental-permission
180-
Enable the experimental permission model.
179+
.It Fl -permission
180+
Enable the permission model.
181181
.
182182
.It Fl -experimental-shadow-realm
183183
Use this flag to enable ShadowRealm support.

lib/internal/process/permission.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ const { validateString, validateBuffer } = require('internal/validators');
99
const { Buffer } = require('buffer');
1010
const { isBuffer } = Buffer;
1111

12-
let experimentalPermission;
12+
let _permission;
1313

1414
module.exports = ObjectFreeze({
1515
__proto__: null,
1616
isEnabled() {
17-
if (experimentalPermission === undefined) {
17+
if (_permission === undefined) {
1818
const { getOptionValue } = require('internal/options');
19-
experimentalPermission = getOptionValue('--experimental-permission');
19+
_permission = getOptionValue('--permission');
2020
}
21-
return experimentalPermission;
21+
return _permission;
2222
},
2323
has(scope, reference) {
2424
validateString(scope, 'scope');

lib/internal/process/pre_execution.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,13 @@ function initializeClusterIPC() {
520520
}
521521

522522
function initializePermission() {
523-
const experimentalPermission = getOptionValue('--experimental-permission');
524-
if (experimentalPermission) {
523+
const permission = getOptionValue('--permission');
524+
if (permission) {
525525
process.binding = function binding(_module) {
526526
throw new ERR_ACCESS_DENIED('process.binding');
527527
};
528528
// Guarantee path module isn't monkey-patched to bypass permission model
529529
ObjectFreeze(require('path'));
530-
emitExperimentalWarning('Permission');
531530
const { has } = require('internal/process/permission');
532531
const warnFlags = [
533532
'--allow-addons',
@@ -579,7 +578,7 @@ function initializePermission() {
579578
ArrayPrototypeForEach(availablePermissionFlags, (flag) => {
580579
const value = getOptionValue(flag);
581580
if (value.length) {
582-
throw new ERR_MISSING_OPTION('--experimental-permission');
581+
throw new ERR_MISSING_OPTION('--permission');
583582
}
584583
});
585584
}

src/env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ Environment::Environment(IsolateData* isolate_data,
918918
std::move(traced_value));
919919
}
920920

921-
if (options_->experimental_permission) {
921+
if (options_->permission) {
922922
permission()->EnablePermissions();
923923
// The process shouldn't be able to neither
924924
// spawn/worker nor use addons or enable inspector

0 commit comments

Comments
 (0)