Skip to content

Commit 0bcb1d6

Browse files
jakobkummerowCommit Bot
authored andcommitted
[flags] Introduce --disallow-code-generation-from-strings
Exposing the existing Context::AllowCodeGenerationFromStrings(false) API to the command line. Bug: v8:7134 Change-Id: I062ccff0b03c5bcf6878c41c455c0ded37a1d743 Reviewed-on: https://chromium-review.googlesource.com/809631 Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#49911}
1 parent 75c1c6c commit 0bcb1d6

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/bootstrapper.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,6 +5484,11 @@ Genesis::Genesis(
54845484
if (!InstallDebuggerNatives()) return;
54855485
}
54865486

5487+
if (FLAG_disallow_code_generation_from_strings) {
5488+
native_context()->set_allow_code_gen_from_strings(
5489+
isolate->heap()->false_value());
5490+
}
5491+
54875492
ConfigureUtilsObject(context_type);
54885493

54895494
// Check that the script context table is empty except for the 'this' binding.

src/flag-definitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ DEFINE_BOOL(builtins_in_stack_traces, false,
759759
"show built-in functions in stack traces")
760760
DEFINE_BOOL(enable_experimental_builtins, true,
761761
"enable new csa-based experimental builtins")
762+
DEFINE_BOOL(disallow_code_generation_from_strings, false,
763+
"disallow eval and friends")
762764

763765
// builtins.cc
764766
DEFINE_BOOL(allow_unsafe_function_constructor, false,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --disallow-code-generation-from-strings
6+
7+
assertThrows("1 + 1", EvalError);
8+
assertThrows(() => eval("1 + 1"), EvalError);
9+
assertThrows(() => Function("x", "return x + 1"), EvalError);

0 commit comments

Comments
 (0)