feat: allow more Node.js cli flags in main process (#39344)

* feat: allow more Node.js cli flags in main process

* docs: update cli switch documentation
This commit is contained in:
Shelley Vohr 2023-08-04 12:59:40 +02:00 committed by GitHub
parent c5b9f766f3
commit 2e0517c0ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 19 deletions

View file

@ -228,21 +228,30 @@ void ErrorMessageListener(v8::Local<v8::Message> message,
}
}
// Only allow DebugOptions in non-ELECTRON_RUN_AS_NODE mode.
// Only allow a specific subset of options in non-ELECTRON_RUN_AS_NODE mode.
// If node CLI inspect support is disabled, allow no debug options.
bool IsAllowedDebugOption(base::StringPiece option) {
static constexpr auto options = base::MakeFixedFlatSet<base::StringPiece>({
"--debug",
"--debug-brk",
"--debug-port",
"--inspect",
"--inspect-brk",
"--inspect-brk-node",
"--inspect-port",
"--inspect-publish-uid",
});
bool IsAllowedOption(base::StringPiece option) {
static constexpr auto debug_options =
base::MakeFixedFlatSet<base::StringPiece>({
"--debug",
"--debug-brk",
"--debug-port",
"--inspect",
"--inspect-brk",
"--inspect-brk-node",
"--inspect-port",
"--inspect-publish-uid",
});
return electron::fuses::IsNodeCliInspectEnabled() && options.contains(option);
// This should be aligned with what's possible to set via the process object.
static constexpr auto options = base::MakeFixedFlatSet<base::StringPiece>(
{"--trace-warnings", "--trace-deprecation", "--throw-deprecation",
"--no-deprecation"});
if (debug_options.contains(option))
return electron::fuses::IsNodeCliInspectEnabled();
return options.contains(option);
}
// Initialize NODE_OPTIONS to pass to Node.js
@ -395,8 +404,9 @@ void NodeBindings::SetNodeCliFlags() {
#endif
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
// Only allow in no-op (--) option or DebugOptions
if (IsAllowedDebugOption(stripped) || stripped == "--")
// Only allow in no-op (--) option or a small set of debug
// and trace related options.
if (IsAllowedOption(stripped) || stripped == "--")
args.push_back(option);
}