Skip to content

Commit fce6acc

Browse files
committed
src: fix external module env and kDisableNodeOptionsEnv
1 parent 951af83 commit fce6acc

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

doc/api/cli.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,13 @@ equivalent to using the `--redirect-warnings=file` command-line flag.
27802780
added:
27812781
- v13.0.0
27822782
- v12.16.0
2783+
changes:
2784+
- version:
2785+
- REPLACEME
2786+
pr-url: TBD
2787+
description:
2788+
Remove the possibility to use this env var with
2789+
kDisableNodeOptionsEnv for embedders.
27832790
-->
27842791

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

src/node.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,15 @@ static ExitCode InitializeNodeWithArgsInternal(
896896
&env_argv, nullptr, errors, kAllowedInEnvvar);
897897
if (exit_code != ExitCode::kNoFailure) return exit_code;
898898
}
899+
} else {
900+
std::string node_repl_external_env = {};
901+
if (credentials::SafeGetenv("NODE_REPL_EXTERNAL_MODULE",
902+
&node_repl_external_env) ||
903+
!node_repl_external_env.empty()) {
904+
errors->emplace_back("NODE_REPL_EXTERNAL_MODULE can't be used with "
905+
"kDisableNodeOptionsEnv");
906+
return ExitCode::kBootstrapFailure;
907+
}
899908
}
900909
#endif
901910

test/embedding/embedtest.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ int main(int argc, char** argv) {
3333
std::shared_ptr<node::InitializationResult> result =
3434
node::InitializeOncePerProcess(
3535
args,
36-
{node::ProcessInitializationFlags::kNoInitializeV8,
37-
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform});
36+
{
37+
node::ProcessInitializationFlags::kNoInitializeV8,
38+
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform,
39+
node::ProcessInitializationFlags::kDisableNodeOptionsEnv,
40+
});
3841

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

test/embedding/test-embedding.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,20 @@ 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+
'NODE_REPL_EXTERNAL_MODULE': 'fs',
163+
},
164+
},
165+
{
166+
status: 10,
167+
signal: null,
168+
stderr: `${binary}: NODE_REPL_EXTERNAL_MODULE can't be used with kDisableNodeOptionsEnv\n`,
169+
});
170+
}

0 commit comments

Comments
 (0)