Skip to content

Commit efcc5d9

Browse files
RafaelGSSaduh95
authored andcommitted
src,lib: stabilize permission model
Move permission model from 1.1 (Active Development) to 2.0 (Stable). PR-URL: #56201 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 7b2a6ee commit efcc5d9

File tree

53 files changed

+143
-147
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

+143
-147
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: 37 additions & 26 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
^
@@ -189,12 +189,15 @@ Error: Access to this API has been restricted
189189
<!-- YAML
190190
added: v20.0.0
191191
changes:
192+
- version: REPLACEME
193+
pr-url: https://github.com/nodejs/node/pull/56201
194+
description: Permission Model and --allow-fs flags are stable.
192195
- version: v20.7.0
193196
pr-url: https://github.com/nodejs/node/pull/49047
194197
description: Paths delimited by comma (`,`) are no longer allowed.
195198
-->
196199

197-
> Stability: 1.1 - Active development
200+
> Stability: 2 - Stable.
198201
199202
This flag configures file system read permissions using
200203
the [Permission Model][].
@@ -210,7 +213,7 @@ Examples can be found in the [File System Permissions][] documentation.
210213
The initializer module also needs to be allowed. Consider the following example:
211214

212215
```console
213-
$ node --experimental-permission index.js
216+
$ node --permission index.js
214217

215218
Error: Access to this API has been restricted
216219
at node:internal/main/run_main_module:23:47 {
@@ -223,20 +226,23 @@ Error: Access to this API has been restricted
223226
The process needs to have access to the `index.js` module:
224227

225228
```bash
226-
node --experimental-permission --allow-fs-read=/path/to/index.js index.js
229+
node --permission --allow-fs-read=/path/to/index.js index.js
227230
```
228231

229232
### `--allow-fs-write`
230233

231234
<!-- YAML
232235
added: v20.0.0
233236
changes:
237+
- version: REPLACEME
238+
pr-url: https://github.com/nodejs/node/pull/56201
239+
description: Permission Model and --allow-fs flags are stable.
234240
- version: v20.7.0
235241
pr-url: https://github.com/nodejs/node/pull/49047
236242
description: Paths delimited by comma (`,`) are no longer allowed.
237243
-->
238244

239-
> Stability: 1.1 - Active development
245+
> Stability: 2 - Stable.
240246
241247
This flag configures file system write permissions using
242248
the [Permission Model][].
@@ -282,7 +288,7 @@ new WASI({
282288
```
283289

284290
```console
285-
$ node --experimental-permission --allow-fs-read=* index.js
291+
$ node --permission --allow-fs-read=* index.js
286292

287293
Error: Access to this API has been restricted
288294
at node:internal/main/run_main_module:30:49 {
@@ -313,7 +319,7 @@ new Worker(__filename);
313319
```
314320

315321
```console
316-
$ node --experimental-permission --allow-fs-read=* index.js
322+
$ node --permission --allow-fs-read=* index.js
317323

318324
Error: Access to this API has been restricted
319325
at node:internal/main/run_main_module:17:47 {
@@ -949,24 +955,6 @@ added:
949955
950956
Enable experimental support for the network inspection with Chrome DevTools.
951957

952-
### `--experimental-permission`
953-
954-
<!-- YAML
955-
added: v20.0.0
956-
-->
957-
958-
> Stability: 1.1 - Active development
959-
960-
Enable the Permission Model for current process. When enabled, the
961-
following permissions are restricted:
962-
963-
* File System - manageable through
964-
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
965-
* Child Process - manageable through [`--allow-child-process`][] flag
966-
* Worker Threads - manageable through [`--allow-worker`][] flag
967-
* WASI - manageable through [`--allow-wasi`][] flag
968-
* Addons - manageable through [`--allow-addons`][] flag
969-
970958
### `--experimental-print-required-tla`
971959

972960
<!-- YAML
@@ -1780,6 +1768,28 @@ unless either the `--pending-deprecation` command-line flag, or the
17801768
are used to provide a kind of selective "early warning" mechanism that
17811769
developers may leverage to detect deprecated API usage.
17821770

1771+
### `--permission`
1772+
1773+
<!-- YAML
1774+
added: v20.0.0
1775+
changes:
1776+
- version: REPLACEME
1777+
pr-url: https://github.com/nodejs/node/pull/56201
1778+
description: Permission Model is now stable.
1779+
-->
1780+
1781+
> Stability: 2 - Stable.
1782+
1783+
Enable the Permission Model for current process. When enabled, the
1784+
following permissions are restricted:
1785+
1786+
* File System - manageable through
1787+
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
1788+
* Child Process - manageable through [`--allow-child-process`][] flag
1789+
* Worker Threads - manageable through [`--allow-worker`][] flag
1790+
* WASI - manageable through [`--allow-wasi`][] flag
1791+
* Addons - manageable through [`--allow-addons`][] flag
1792+
17831793
### `--preserve-symlinks`
17841794

17851795
<!-- YAML
@@ -3089,6 +3099,7 @@ one is included in the list below.
30893099
* `--openssl-legacy-provider`
30903100
* `--openssl-shared-config`
30913101
* `--pending-deprecation`
3102+
* `--permission`
30923103
* `--preserve-symlinks-main`
30933104
* `--preserve-symlinks`
30943105
* `--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 - 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:
@@ -167,5 +165,5 @@ There are constraints you need to know before using this system:
167165
[`--allow-fs-write`]: cli.md#--allow-fs-write
168166
[`--allow-wasi`]: cli.md#--allow-wasi
169167
[`--allow-worker`]: cli.md#--allow-worker
170-
[`--experimental-permission`]: cli.md#--experimental-permission
168+
[`--permission`]: cli.md#--permission
171169
[`permission.has()`]: process.md#processpermissionhasscope-reference

doc/api/process.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ added: v20.0.0
31033103
31043104
* {Object}
31053105
3106-
This API is available through the [`--experimental-permission`][] flag.
3106+
This API is available through the [`--permission`][] flag.
31073107
31083108
`process.permission` is an object whose methods are used to manage permissions
31093109
for the current process. Additional documentation is available in the
@@ -4440,8 +4440,8 @@ cases:
44404440
[`'exit'`]: #event-exit
44414441
[`'message'`]: child_process.md#event-message
44424442
[`'uncaughtException'`]: #event-uncaughtexception
4443-
[`--experimental-permission`]: cli.md#--experimental-permission
44444443
[`--no-deprecation`]: cli.md#--no-deprecation
4444+
[`--permission`]: cli.md#--permission
44454445
[`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
44464446
[`Buffer`]: buffer.md
44474447
[`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)
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