Skip to content

Commit bb4146a

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

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
@@ -123,7 +123,7 @@ require('nodejs-addon-example');
123123
```
124124

125125
```console
126-
$ node --experimental-permission --allow-fs-read=* index.js
126+
$ node --permission --allow-fs-read=* index.js
127127
node:internal/modules/cjs/loader:1319
128128
return process.dlopen(module, path.toNamespacedPath(filename));
129129
^
@@ -165,7 +165,7 @@ childProcess.spawn('node', ['-e', 'require("fs").writeFileSync("/new-file", "exa
165165
```
166166

167167
```console
168-
$ node --experimental-permission --allow-fs-read=* index.js
168+
$ node --permission --allow-fs-read=* index.js
169169
node:internal/child_process:388
170170
const err = this._handle.spawn(options);
171171
^
@@ -194,7 +194,7 @@ changes:
194194
description: Paths delimited by comma (`,`) are no longer allowed.
195195
-->
196196

197-
> Stability: 1.1 - Active development
197+
> Stability: 2.0 - Stable.
198198
199199
This flag configures file system read permissions using
200200
the [Permission Model][].
@@ -210,7 +210,7 @@ Examples can be found in the [File System Permissions][] documentation.
210210
The initializer module also needs to be allowed. Consider the following example:
211211

212212
```console
213-
$ node --experimental-permission index.js
213+
$ node --permission index.js
214214

215215
Error: Access to this API has been restricted
216216
at node:internal/main/run_main_module:23:47 {
@@ -223,7 +223,7 @@ Error: Access to this API has been restricted
223223
The process needs to have access to the `index.js` module:
224224

225225
```bash
226-
node --experimental-permission --allow-fs-read=/path/to/index.js index.js
226+
node --permission --allow-fs-read=/path/to/index.js index.js
227227
```
228228

229229
### `--allow-fs-write`
@@ -236,7 +236,7 @@ changes:
236236
description: Paths delimited by comma (`,`) are no longer allowed.
237237
-->
238238

239-
> Stability: 1.1 - Active development
239+
> Stability: 2.0 - Stable.
240240
241241
This flag configures file system write permissions using
242242
the [Permission Model][].
@@ -282,7 +282,7 @@ new WASI({
282282
```
283283

284284
```console
285-
$ node --experimental-permission --allow-fs-read=* index.js
285+
$ node --permission --allow-fs-read=* index.js
286286

287287
Error: Access to this API has been restricted
288288
at node:internal/main/run_main_module:30:49 {
@@ -313,7 +313,7 @@ new Worker(__filename);
313313
```
314314

315315
```console
316-
$ node --experimental-permission --allow-fs-read=* index.js
316+
$ node --permission --allow-fs-read=* index.js
317317

318318
Error: Access to this API has been restricted
319319
at node:internal/main/run_main_module:17:47 {
@@ -935,13 +935,17 @@ added:
935935
936936
Enable experimental support for the network inspection with Chrome DevTools.
937937

938-
### `--experimental-permission`
938+
### `--permission`
939939

940940
<!-- YAML
941941
added: v20.0.0
942+
changes:
943+
- version: REPLACEME
944+
pr-url: https://github.com/nodejs/node/pull/56201
945+
description: Permission Model is now stable.
942946
-->
943947

944-
> Stability: 1.1 - Active development
948+
> Stability: 2.0 - Stable
945949
946950
Enable the Permission Model for current process. When enabled, the
947951
following permissions are restricted:
@@ -3027,7 +3031,6 @@ one is included in the list below.
30273031
* `--experimental-json-modules`
30283032
* `--experimental-loader`
30293033
* `--experimental-modules`
3030-
* `--experimental-permission`
30313034
* `--experimental-print-required-tla`
30323035
* `--experimental-require-module`
30333036
* `--experimental-shadow-realm`
@@ -3080,6 +3083,7 @@ one is included in the list below.
30803083
* `--openssl-legacy-provider`
30813084
* `--openssl-shared-config`
30823085
* `--pending-deprecation`
3086+
* `--permission`
30833087
* `--preserve-symlinks-main`
30843088
* `--preserve-symlinks`
30853089
* `--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
@@ -3107,7 +3107,7 @@ added: v20.0.0
31073107
31083108
* {Object}
31093109
3110-
This API is available through the [`--experimental-permission`][] flag.
3110+
This API is available through the [`--permission`][] flag.
31113111
31123112
`process.permission` is an object whose methods are used to manage permissions
31133113
for the current process. Additional documentation is available in the
@@ -4444,8 +4444,8 @@ cases:
44444444
[`'exit'`]: #event-exit
44454445
[`'message'`]: child_process.md#event-message
44464446
[`'uncaughtException'`]: #event-uncaughtexception
4447-
[`--experimental-permission`]: cli.md#--experimental-permission
44484447
[`--no-deprecation`]: cli.md#--no-deprecation
4448+
[`--permission`]: cli.md#--permission
44494449
[`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
44504450
[`Buffer`]: buffer.md
44514451
[`ChildProcess.disconnect()`]: child_process.md#subprocessdisconnect

doc/node.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ Specify the
171171
.Ar module
172172
to use as a custom module loader.
173173
.
174-
.It Fl -experimental-permission
175-
Enable the experimental permission model.
174+
.It Fl -permission
175+
Enable the permission model.
176176
.
177177
.It Fl -experimental-shadow-realm
178178
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
@@ -920,7 +920,7 @@ Environment::Environment(IsolateData* isolate_data,
920920
std::move(traced_value));
921921
}
922922

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

0 commit comments

Comments
 (0)