mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src,permission: restrict by default when pm enabled
PR-URL: https://github.com/nodejs/node/pull/48907 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
1 parent
bcaf198900
commit
14e7bd84f1
2 files changed
+24
-12
No files matched your search
+9
-11
@@ -844,19 +844,17 @@ Environment::Environment(IsolateData* isolate_data,
|
||||
|
||||
if (options_->experimental_permission) {
|
||||
permission()->EnablePermissions();
|
||||
// If any permission is set the process shouldn't be able to neither
|
||||
// The process shouldn't be able to neither
|
||||
// spawn/worker nor use addons or enable inspector
|
||||
// unless explicitly allowed by the user
|
||||
if (!options_->allow_fs_read.empty() || !options_->allow_fs_write.empty()) {
|
||||
options_->allow_native_addons = false;
|
||||
flags_ = flags_ | EnvironmentFlags::kNoCreateInspector;
|
||||
permission()->Apply("*", permission::PermissionScope::kInspector);
|
||||
if (!options_->allow_child_process) {
|
||||
permission()->Apply("*", permission::PermissionScope::kChildProcess);
|
||||
}
|
||||
if (!options_->allow_worker_threads) {
|
||||
permission()->Apply("*", permission::PermissionScope::kWorkerThreads);
|
||||
}
|
||||
options_->allow_native_addons = false;
|
||||
flags_ = flags_ | EnvironmentFlags::kNoCreateInspector;
|
||||
permission()->Apply("*", permission::PermissionScope::kInspector);
|
||||
if (!options_->allow_child_process) {
|
||||
permission()->Apply("*", permission::PermissionScope::kChildProcess);
|
||||
}
|
||||
if (!options_->allow_worker_threads) {
|
||||
permission()->Apply("*", permission::PermissionScope::kWorkerThreads);
|
||||
}
|
||||
|
||||
if (!options_->allow_fs_read.empty()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Flags: --experimental-permission --allow-fs-read=*
|
||||
// Flags: --experimental-permission --allow-fs-read=* --allow-child-process
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
@@ -7,6 +7,7 @@ common.skipIfInspectorDisabled();
|
||||
|
||||
const { Session } = require('inspector');
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('no crypto');
|
||||
@@ -20,3 +21,16 @@ if (!common.hasCrypto)
|
||||
permission: 'Inspector',
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const { status, stderr } = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
'--experimental-permission',
|
||||
'-e',
|
||||
'(new (require("inspector")).Session()).connect()',
|
||||
],
|
||||
);
|
||||
assert.strictEqual(status, 1);
|
||||
assert.match(stderr.toString(), /Error: Access to this API has been restricted/);
|
||||
}
|
||||
Reference in new issue
Block a user