Skip to content

Commit 92ea669

Browse files
RafaelGSStargos
authored andcommitted
src,permission: add --allow-inspector ability
Refs: #48534 PR-URL: #59711 Backport-PR-URL: #60248 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent 1e9abe0 commit 92ea669

File tree

13 files changed

+110
-4
lines changed

13 files changed

+110
-4
lines changed

doc/api/cli.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,36 @@ When passing a single flag with a comma a warning will be displayed.
263263

264264
Examples can be found in the [File System Permissions][] documentation.
265265

266+
### `--allow-inspector`
267+
268+
<!-- YAML
269+
added: REPLACEME
270+
-->
271+
272+
> Stability: 1.0 - Early development
273+
274+
When using the [Permission Model][], the process will not be able to connect
275+
through inspector protocol.
276+
277+
Attempts to do so will throw an `ERR_ACCESS_DENIED` unless the
278+
user explicitly passes the `--allow-inspector` flag when starting Node.js.
279+
280+
Example:
281+
282+
```js
283+
const { Session } = require('node:inspector/promises');
284+
285+
const session = new Session();
286+
session.connect();
287+
```
288+
289+
```console
290+
$ node --permission index.js
291+
Error: connect ERR_ACCESS_DENIED Access to this API has been restricted. Use --allow-inspector to manage permissions.
292+
code: 'ERR_ACCESS_DENIED',
293+
}
294+
```
295+
266296
### `--allow-wasi`
267297

268298
<!-- YAML
@@ -3382,6 +3412,7 @@ one is included in the list below.
33823412
* `--allow-child-process`
33833413
* `--allow-fs-read`
33843414
* `--allow-fs-write`
3415+
* `--allow-inspector`
33853416
* `--allow-wasi`
33863417
* `--allow-worker`
33873418
* `--conditions`, `-C`

doc/node-config-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
}
4646
]
4747
},
48+
"allow-inspector": {
49+
"type": "boolean"
50+
},
4851
"allow-wasi": {
4952
"type": "boolean"
5053
},

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Allow using native addons when using the permission model.
8585
.It Fl -allow-child-process
8686
Allow spawning process when using the permission model.
8787
.
88+
.It Fl -allow-inspector
89+
Allow inspector access when using the permission model.
90+
.
8891
.It Fl -allow-wasi
8992
Allow execution of WASI when using the permission model.
9093
.

lib/internal/process/permission.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = ObjectFreeze({
3939
'--allow-fs-write',
4040
'--allow-addons',
4141
'--allow-child-process',
42+
'--allow-inspector',
4243
'--allow-wasi',
4344
'--allow-worker',
4445
];

lib/internal/process/pre_execution.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ function initializePermission() {
613613
const warnFlags = [
614614
'--allow-addons',
615615
'--allow-child-process',
616+
'--allow-inspector',
616617
'--allow-wasi',
617618
'--allow-worker',
618619
];

src/env.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,10 @@ Environment::Environment(IsolateData* isolate_data,
912912
options_->allow_native_addons = false;
913913
permission()->Apply(this, {"*"}, permission::PermissionScope::kAddon);
914914
}
915-
flags_ = flags_ | EnvironmentFlags::kNoCreateInspector;
916-
permission()->Apply(this, {"*"}, permission::PermissionScope::kInspector);
915+
if (!options_->allow_inspector) {
916+
flags_ = flags_ | EnvironmentFlags::kNoCreateInspector;
917+
permission()->Apply(this, {"*"}, permission::PermissionScope::kInspector);
918+
}
917919
if (!options_->allow_child_process) {
918920
permission()->Apply(
919921
this, {"*"}, permission::PermissionScope::kChildProcess);

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
614614
"allow use of child process when any permissions are set",
615615
&EnvironmentOptions::allow_child_process,
616616
kAllowedInEnvvar);
617+
AddOption("--allow-inspector",
618+
"allow use of inspector when any permissions are set",
619+
&EnvironmentOptions::allow_inspector,
620+
kAllowedInEnvvar);
617621
AddOption("--allow-wasi",
618622
"allow wasi when any permissions are set",
619623
&EnvironmentOptions::allow_wasi,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class EnvironmentOptions : public Options {
140140
std::vector<std::string> allow_fs_read;
141141
std::vector<std::string> allow_fs_write;
142142
bool allow_addons = false;
143+
bool allow_inspector = false;
143144
bool allow_child_process = false;
144145
bool allow_wasi = false;
145146
bool allow_worker_threads = false;

src/permission/permission_base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace permission {
2727
#define WORKER_THREADS_PERMISSIONS(V) \
2828
V(WorkerThreads, "worker", PermissionsRoot, "--allow-worker")
2929

30-
#define INSPECTOR_PERMISSIONS(V) V(Inspector, "inspector", PermissionsRoot, "")
30+
#define INSPECTOR_PERMISSIONS(V) \
31+
V(Inspector, "inspector", PermissionsRoot, "--allow-inspector")
3132

3233
#define ADDON_PERMISSIONS(V) \
3334
V(Addon, "addon", PermissionsRoot, "--allow-addons")

test/common/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ if (hasCrypto) {
365365
knownGlobals.add(globalThis.SubtleCrypto);
366366
}
367367

368+
const { Worker } = require('node:worker_threads');
369+
knownGlobals.add(Worker);
370+
368371
function allowGlobals(...allowlist) {
369372
for (const val of allowlist) {
370373
knownGlobals.add(val);

0 commit comments

Comments
 (0)