Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: sync NODE_REPL_EXTERNAL_MODULE and kDisableNodeOptionsEnv #52905

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,13 @@ equivalent to using the `--redirect-warnings=file` command-line flag.
added:
- v13.0.0
- v12.16.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/52905
description:
Remove the possibility to use this env var with
kDisableNodeOptionsEnv for embedders.
Comment on lines +2847 to +2853

This comment was marked as resolved.

This comment was marked as resolved.

-->

Path to a Node.js module which will be loaded in place of the built-in REPL.
Expand Down
9 changes: 9 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,15 @@ static ExitCode InitializeNodeWithArgsInternal(
&env_argv, nullptr, errors, kAllowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) return exit_code;
}
} else {
std::string node_repl_external_env = {};
if (credentials::SafeGetenv("NODE_REPL_EXTERNAL_MODULE",
&node_repl_external_env) ||
!node_repl_external_env.empty()) {
errors->emplace_back("NODE_REPL_EXTERNAL_MODULE can't be used with "
"kDisableNodeOptionsEnv");
return ExitCode::kInvalidCommandLineArgument;
}
}
#endif

Expand Down
11 changes: 9 additions & 2 deletions test/embedding/embedtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ int main(int argc, char** argv) {
std::shared_ptr<node::InitializationResult> result =
node::InitializeOncePerProcess(
args,
{node::ProcessInitializationFlags::kNoInitializeV8,
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform});
{
node::ProcessInitializationFlags::kNoInitializeV8,
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform,
// This is used to test NODE_REPL_EXTERNAL_MODULE is disabled with
// kDisableNodeOptionsEnv. If other tests need NODE_OPTIONS
// support in the future, split this configuration out as a
// command line option.
node::ProcessInitializationFlags::kDisableNodeOptionsEnv,
RafaelGSS marked this conversation as resolved.
Show resolved Hide resolved
});

for (const std::string& error : result->errors())
fprintf(stderr, "%s: %s\n", args[0].c_str(), error.c_str());
Expand Down
18 changes: 18 additions & 0 deletions test/embedding/test-embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,21 @@ for (const extraSnapshotArgs of [
[ '--', ...runEmbeddedArgs ],
{ cwd: tmpdir.path });
}

// Guarantee NODE_REPL_EXTERNAL_MODULE won't bypass kDisableNodeOptionsEnv
{
spawnSyncAndExit(
binary,
['require("os")'],
{
env: {
...process.env,
'NODE_REPL_EXTERNAL_MODULE': 'fs',
},
},
{
status: 9,
signal: null,
stderr: `${binary}: NODE_REPL_EXTERNAL_MODULE can't be used with kDisableNodeOptionsEnv\n`,
});
}