Skip to content

Commit 57d302b

Browse files
joyeecheungtargos
authored andcommitted
process: delay creation of process.env after bootstrap/node.js
Make sure that no code is allowed to access process.env during the execution of bootstrap/node.js. PR-URL: #26515 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent cc4a25a commit 57d302b

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/node.cc

+10
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
350350
MaybeLocal<Value> result = ExecuteBootstrapper(
351351
env, "internal/bootstrap/node", &node_params, &node_args);
352352

353+
Local<Object> env_var_proxy;
354+
if (!CreateEnvVarProxy(context, isolate, env->as_callback_data())
355+
.ToLocal(&env_var_proxy) ||
356+
process
357+
->Set(env->context(),
358+
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
359+
env_var_proxy)
360+
.IsNothing())
361+
return MaybeLocal<Value>();
362+
353363
env->set_has_run_bootstrapping_code(true);
354364

355365
return scope.EscapeMaybe(result);

src/node_process_object.cc

-12
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ MaybeLocal<Object> CreateProcessObject(
151151
ToV8Value(env->context(), exec_args)
152152
.ToLocalChecked()).FromJust();
153153

154-
Local<Object> env_var_proxy;
155-
if (!CreateEnvVarProxy(context, isolate, env->as_callback_data())
156-
.ToLocal(&env_var_proxy))
157-
return MaybeLocal<Object>();
158-
159-
// process.env
160-
process
161-
->Set(env->context(),
162-
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
163-
env_var_proxy)
164-
.FromJust();
165-
166154
READONLY_PROPERTY(process, "pid",
167155
Integer::New(env->isolate(), uv_os_getpid()));
168156

0 commit comments

Comments
 (0)