Skip to content

Commit 3b79e9c

Browse files
RafaelGSSmarco-ippolito
authored andcommitted
src: fix external module env and kDisableNodeOptionsEnv
PR-URL: #52905 Fixes: #51227 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent dfa4986 commit 3b79e9c

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

doc/api/cli.md

+7
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,13 @@ equivalent to using the `--redirect-warnings=file` command-line flag.
27322732
added:
27332733
- v13.0.0
27342734
- v12.16.0
2735+
changes:
2736+
- version:
2737+
- REPLACEME
2738+
pr-url: https://github.com/nodejs/node/pull/52905
2739+
description:
2740+
Remove the possibility to use this env var with
2741+
kDisableNodeOptionsEnv for embedders.
27352742
-->
27362743

27372744
Path to a Node.js module which will be loaded in place of the built-in REPL.

src/node.cc

+9
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,15 @@ static ExitCode InitializeNodeWithArgsInternal(
919919
&env_argv, nullptr, errors, kAllowedInEnvvar);
920920
if (exit_code != ExitCode::kNoFailure) return exit_code;
921921
}
922+
} else {
923+
std::string node_repl_external_env = {};
924+
if (credentials::SafeGetenv("NODE_REPL_EXTERNAL_MODULE",
925+
&node_repl_external_env) ||
926+
!node_repl_external_env.empty()) {
927+
errors->emplace_back("NODE_REPL_EXTERNAL_MODULE can't be used with "
928+
"kDisableNodeOptionsEnv");
929+
return ExitCode::kInvalidCommandLineArgument;
930+
}
922931
}
923932
#endif
924933

test/embedding/embedtest.cc

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ NODE_MAIN(int argc, node::argv_type raw_argv[]) {
3535
std::unique_ptr<node::InitializationResult> result =
3636
node::InitializeOncePerProcess(
3737
args,
38-
{node::ProcessInitializationFlags::kNoInitializeV8,
39-
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform});
38+
{
39+
node::ProcessInitializationFlags::kNoInitializeV8,
40+
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform,
41+
// This is used to test NODE_REPL_EXTERNAL_MODULE is disabled with
42+
// kDisableNodeOptionsEnv. If other tests need NODE_OPTIONS
43+
// support in the future, split this configuration out as a
44+
// command line option.
45+
node::ProcessInitializationFlags::kDisableNodeOptionsEnv,
46+
});
4047

4148
for (const std::string& error : result->errors())
4249
fprintf(stderr, "%s: %s\n", args[0].c_str(), error.c_str());

test/embedding/test-embedding.js

+18
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,21 @@ for (const extraSnapshotArgs of [
151151
[ '--', ...runEmbeddedArgs ],
152152
{ cwd: tmpdir.path });
153153
}
154+
155+
// Guarantee NODE_REPL_EXTERNAL_MODULE won't bypass kDisableNodeOptionsEnv
156+
{
157+
spawnSyncAndExit(
158+
binary,
159+
['require("os")'],
160+
{
161+
env: {
162+
...process.env,
163+
'NODE_REPL_EXTERNAL_MODULE': 'fs',
164+
},
165+
},
166+
{
167+
status: 9,
168+
signal: null,
169+
stderr: `${binary}: NODE_REPL_EXTERNAL_MODULE can't be used with kDisableNodeOptionsEnv\n`,
170+
});
171+
}

0 commit comments

Comments
 (0)