Skip to content

Commit 1cd5347

Browse files
fix: classify complete NodeVM run arguments
1 parent 3216b97 commit 1cd5347

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎SHA256SUMS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c513513958376d2915b026a3f869d31211f798ad4c48c4d0a5e97ff6be3b0652 vm2_nesting_check.py
1+
10826257b222e4d6b430b3a38f05b8c89042eaabc95cd26316fefd8a50e06857 vm2_nesting_check.py

‎test_source.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_comments_strings_templates_regex_and_unrelated_constructors(self):
8484

8585
def test_run_argument_shape_is_never_trust_or_taint(self):
8686
prefix = "const {NodeVM} = require('vm2'); const sandbox = new NodeVM({nesting:true, require:[]});"
87-
for expression, expected in [("'static text'", "literal_string"), ("request.body.code", "dynamic_or_unsupported"), ("trustedCode", "dynamic_or_unsupported"), ("`template`", "dynamic_or_unsupported")]:
87+
for expression, expected in [("'static text'", "literal_string"), ("'vm2'", "literal_string"), ("'nesting'", "literal_string"), ("'require'", "literal_string"), ("'prefix' + request.body.code", "dynamic_or_unsupported"), ("'literal', 'filename'", "literal_string"), ("request.body.code", "dynamic_or_unsupported"), ("trustedCode", "dynamic_or_unsupported"), ("`template`", "dynamic_or_unsupported")]:
8888
row = self.scan(prefix + "sandbox.run(" + expression + ");")[0]
8989
self.assertEqual(expected, row["source_run_argument"])
9090
self.assertEqual("not_reported", row["precondition_attacker_supplied_javascript_executed"])

‎vm2_nesting_check.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ def scan_source_text(text, relative_path):
415415
runs = {}
416416
for index in range(len(values) - 4):
417417
if values[index + 1:index + 4] == [".", "run", "("]:
418-
shape = "literal_string" if values[index + 4] == "@string" else "dynamic_or_unsupported"
418+
first = index + 4
419+
quoted = values[first] in {"@string", "@vm2", "@nesting", "@require"}
420+
single = first + 1 == pairs[index + 3] or (first + 1 < len(values) and values[first + 1] == ",")
421+
shape = "literal_string" if quoted and single else "dynamic_or_unsupported"
419422
runs.setdefault(values[index], set()).add(shape)
420423
rows = []
421424
for index, value in enumerate(values[:-2]):

0 commit comments

Comments
 (0)