diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index b4ed16573e1e07..344b56718463b1 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -508,11 +508,10 @@ return NativeModule._source.hasOwnProperty(id); }; - const EXPOSE_INTERNALS = process.execArgv.some(function(arg) { - return arg.match(/^--expose[-_]internals$/); - }); + const EXPOSE_INTERNALS = process._exposeInternals; if (EXPOSE_INTERNALS) { + delete process._exposeInternals; NativeModule.nonInternalExists = NativeModule.exists; NativeModule.isInternal = function(id) { diff --git a/src/node.cc b/src/node.cc index 8abbf9c59a7f02..8f20151b417a1e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -163,6 +163,7 @@ static bool trace_sync_io = false; static bool track_heap_objects = false; static const char* eval_string = nullptr; static std::vector preload_modules; +static bool expose_internals = false; static const int v8_default_thread_pool_size = 4; static int v8_thread_pool_size = v8_default_thread_pool_size; static bool prof_process = false; @@ -3333,6 +3334,13 @@ void SetupProcessObject(Environment* env, READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate())); } + // --expose_internals, --expose-internals + // Note that this is not exposed as a process property, it is deleted when + // node's javascript bootstrap code runs. + if (expose_internals) { + READONLY_PROPERTY(process, "_exposeInternals", True(env->isolate())); + } + // --security-revert flags #define V(code, _, __) \ do { \ @@ -3786,7 +3794,7 @@ static void ParseArgs(int* argc, #endif } else if (strcmp(arg, "--expose-internals") == 0 || strcmp(arg, "--expose_internals") == 0) { - // consumed in js + expose_internals = true; } else if (strcmp(arg, "--") == 0) { index += 1; break; diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index 02ddfd87c363fc..c09cb558218ab5 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -5,3 +5,4 @@ require('../common'); const assert = require('assert'); assert.strictEqual(typeof require('internal/freelist').FreeList, 'function'); +assert(!('_exposeInternals' in process), 'no process property is leaked');