Skip to content

Commit 1d89c5d

Browse files
committed
cli: whitelist new V8 flag in NODE_OPTIONS
Explicitly whitelists --disallow-code-generation-from-strings in NODE_OPTIONS as a new V8 flag. This flag prevents strings like eval() from performing code generation. PR-URL: #30094 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 511f67b commit 1d89c5d

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

doc/api/cli.md

+10
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ added: v12.0.0
127127
128128
Specify the file name of the CPU profile generated by `--cpu-prof`.
129129

130+
### `--disallow-code-generation-from-strings`
131+
<!-- YAML
132+
added: v9.8.0
133+
-->
134+
135+
Make built-in language features like `eval` and `new Function` that generate
136+
code from strings throw an exception instead. This does not affect the Node.js
137+
`vm` module.
138+
130139
### `--enable-fips`
131140
<!-- YAML
132141
added: v6.0.0
@@ -1079,6 +1088,7 @@ Node.js options that are allowed are:
10791088
V8 options that are allowed are:
10801089
<!-- node-options-v8 start -->
10811090
* `--abort-on-uncaught-exception`
1091+
* `--disallow-code-generation-from-strings`
10821092
* `--interpreted-frames-native-stack`
10831093
* `--max-old-space-size`
10841094
* `--perf-basic-prof-only-functions`

doc/node.1

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ The default is
100100
File name of the V8 CPU profile generated with
101101
.Fl -cpu-prof
102102
.
103+
.It Fl -disallow-code-generation-from-strings
104+
Make built-in language features like `eval` and `new Function` that generate
105+
code from strings throw an exception instead. This does not affect the Node.js
106+
`vm` module.
107+
.
103108
.It Fl -enable-fips
104109
Enable FIPS-compliant crypto at startup.
105110
Requires Node.js to be built with

src/node_options.cc

+4
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
589589
V8Option{},
590590
kAllowedInEnvironment);
591591
AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment);
592+
AddOption("--disallow-code-generation-from-strings",
593+
"disallow eval and friends",
594+
V8Option{},
595+
kAllowedInEnvironment);
592596

593597
#ifdef NODE_REPORT
594598
AddOption("--report-uncaught-exception",

test/parallel/test-cli-node-options.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (common.hasCrypto) {
6060

6161
// V8 options
6262
expect('--abort_on-uncaught_exception', 'B\n');
63+
expect('--disallow-code-generation-from-strings', 'B\n');
6364
expect('--max-old-space-size=0', 'B\n');
6465
expect('--stack-trace-limit=100',
6566
/(\s*at f \(\[eval\]:1:\d*\)\r?\n){100}/,

0 commit comments

Comments
 (0)