Skip to content

Commit c8316fe

Browse files
committed
src,permission: add --allow-inspector ability
Refs: #48534 PR-URL: #59711 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Signed-off-by: RafaelGSS <[email protected]>
1 parent 56a4a50 commit c8316fe

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
@@ -271,6 +271,36 @@ When passing a single flag with a comma a warning will be displayed.
271271

272272
Examples can be found in the [File System Permissions][] documentation.
273273

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

276306
<!-- YAML
@@ -3373,6 +3403,7 @@ one is included in the list below.
33733403
* `--allow-child-process`
33743404
* `--allow-fs-read`
33753405
* `--allow-fs-write`
3406+
* `--allow-inspector`
33763407
* `--allow-wasi`
33773408
* `--allow-worker`
33783409
* `--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
@@ -580,6 +580,7 @@ function initializePermission() {
580580
const warnFlags = [
581581
'--allow-addons',
582582
'--allow-child-process',
583+
'--allow-inspector',
583584
'--allow-wasi',
584585
'--allow-worker',
585586
];

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
@@ -606,6 +606,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
606606
"allow use of child process when any permissions are set",
607607
&EnvironmentOptions::allow_child_process,
608608
kAllowedInEnvvar);
609+
AddOption("--allow-inspector",
610+
"allow use of inspector when any permissions are set",
611+
&EnvironmentOptions::allow_inspector,
612+
kAllowedInEnvvar);
609613
AddOption("--allow-wasi",
610614
"allow wasi when any permissions are set",
611615
&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
@@ -364,6 +364,9 @@ if (hasCrypto) {
364364
knownGlobals.add(globalThis.SubtleCrypto);
365365
}
366366

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

0 commit comments

Comments
 (0)