src,test: disable freezing V8 flags on initialization

Node.js still changes flags after initializationg; either because
tests need to set their own flags (which V8 tests also still allow),
or because it's explicitly requested via the "v8.setFlagsFromString"
method that Node.js provides.

PR-URL: https://github.com/nodejs/node/pull/44741
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Clemens Backes 2022-06-13 12:38:15 +02:00 committed by Michaël Zasso
parent fd52c62bee
commit 2e49b99cc2
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
2 changed files with 10 additions and 0 deletions

View File

@ -741,6 +741,11 @@ static ExitCode InitializeNodeWithArgsInternal(
// used in diagnostic reports.
per_process::cli_options->cmdline = *argv;
// Node provides a "v8.setFlagsFromString" method to dynamically change flags.
// Hence do not freeze flags when initializing V8. In a browser setting, this
// is security relevant, for Node it's less important.
V8::SetFlagsFromString("--no-freeze-flags-after-init");
#if defined(NODE_V8_OPTIONS)
// Should come before the call to V8::SetFlagsFromCommandLine()
// so the user can disable a flag --foo at run-time by passing

View File

@ -24,6 +24,11 @@ void NodeTestEnvironment::SetUp() {
#endif
cppgc::InitializeProcess(
NodeZeroIsolateTestFixture::platform->GetPageAllocator());
// Before initializing V8, disable the --freeze-flags-after-init flag, so
// individual tests can set their own flags.
v8::V8::SetFlagsFromString("--no-freeze-flags-after-init");
v8::V8::Initialize();
}