Skip to content

Commit 8b07404

Browse files
committed
src: use option parser for expose_internals
bootstrap_node.js was directly parsing process.execArgv to see if internals should be exposed, even though the argv was already parsed by node. This is unusual and unnecessary, change it to set the option value from the parser onto the process object, as is done for the other CLI options.
1 parent 937a3d1 commit 8b07404

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/internal/bootstrap_node.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,10 @@
508508
return NativeModule._source.hasOwnProperty(id);
509509
};
510510

511-
const EXPOSE_INTERNALS = process.execArgv.some(function(arg) {
512-
return arg.match(/^--expose[-_]internals$/);
513-
});
511+
const EXPOSE_INTERNALS = process._exposeInternals;
514512

515513
if (EXPOSE_INTERNALS) {
514+
delete process._exposeInternals;
516515
NativeModule.nonInternalExists = NativeModule.exists;
517516

518517
NativeModule.isInternal = function(id) {

src/node.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ static bool trace_sync_io = false;
163163
static bool track_heap_objects = false;
164164
static const char* eval_string = nullptr;
165165
static std::vector<std::string> preload_modules;
166+
static bool expose_internals = false;
166167
static const int v8_default_thread_pool_size = 4;
167168
static int v8_thread_pool_size = v8_default_thread_pool_size;
168169
static bool prof_process = false;
@@ -3333,6 +3334,13 @@ void SetupProcessObject(Environment* env,
33333334
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
33343335
}
33353336

3337+
// --expose_internals, --expose-internals
3338+
// Note that this is not exposed as a process property, it is deleted when
3339+
// node's javascript bootstrap code runs.
3340+
if (expose_internals) {
3341+
READONLY_PROPERTY(process, "_exposeInternals", True(env->isolate()));
3342+
}
3343+
33363344
// --security-revert flags
33373345
#define V(code, _, __) \
33383346
do { \
@@ -3786,7 +3794,7 @@ static void ParseArgs(int* argc,
37863794
#endif
37873795
} else if (strcmp(arg, "--expose-internals") == 0 ||
37883796
strcmp(arg, "--expose_internals") == 0) {
3789-
// consumed in js
3797+
expose_internals = true;
37903798
} else if (strcmp(arg, "--") == 0) {
37913799
index += 1;
37923800
break;

test/parallel/test-internal-modules-expose.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ require('../common');
55
const assert = require('assert');
66

77
assert.strictEqual(typeof require('internal/freelist').FreeList, 'function');
8+
assert(!('_exposeInternals' in process), 'no process property is leaked');

0 commit comments

Comments
 (0)