Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3196db

Browse filesBrowse files
codebytereMylesBorins
authored andcommitted
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 924a9a8 commit f3196db
Copy full SHA for f3196db

File tree

Expand file treeCollapse file tree

4 files changed

+20
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+20
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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
@@ -1134,6 +1143,7 @@ Node.js options that are allowed are:
11341143
V8 options that are allowed are:
11351144
<!-- node-options-v8 start -->
11361145
* `--abort-on-uncaught-exception`
1146+
* `--disallow-code-generation-from-strings`
11371147
* `--interpreted-frames-native-stack`
11381148
* `--max-old-space-size`
11391149
* `--perf-basic-prof-only-functions`
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+5Lines changed: 5 additions & 0 deletions
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
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
611611
V8Option{},
612612
kAllowedInEnvironment);
613613
AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment);
614+
AddOption("--disallow-code-generation-from-strings",
615+
"disallow eval and friends",
616+
V8Option{},
617+
kAllowedInEnvironment);
614618

615619
#ifdef NODE_REPORT
616620
AddOption("--report-uncaught-exception",
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-cli-node-options.js
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.