Skip to content

Commit 8b3e647

Browse files
author
Max Schaefer
committed
JavaScript: Do not taint for-in loop variable.
1 parent f70e7d7 commit 8b3e647

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

change-notes/1.22/analysis-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- [remote-exec](https://www.npmjs.com/package/remote-exec)
1313

1414
* Support for tracking data flow and taint through getter functions (that is, functions that return a property of one of their arguments) and through the receiver object of method calls has been improved. This may produce more security alerts.
15+
16+
* Taint tracking through object property names has been made more precise, resulting in fewer false positive results.
1517

1618
## New queries
1719

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ module TaintTracking {
231231
succ.(DataFlow::PropRead).getBase() = pred
232232
or
233233
// iterating over a tainted iterator taints the loop variable
234-
exists(EnhancedForLoop efl |
235-
this = DataFlow::valueNode(efl.getIterationDomain()) and
234+
exists(ForOfStmt fos |
235+
this = DataFlow::valueNode(fos.getIterationDomain()) and
236236
pred = this and
237-
succ = DataFlow::ssaDefinitionNode(SSA::definition(efl.getIteratorExpr()))
237+
succ = DataFlow::ssaDefinitionNode(SSA::definition(fos.getIteratorExpr()))
238238
)
239239
}
240240
}

javascript/ql/test/query-tests/Security/CWE-079/tst.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,10 @@ function testCreateContextualFragment() {
285285
var documentFragment = range.createContextualFragment(tainted); // NOT OK
286286
document.body.appendChild(documentFragment);
287287
}
288+
289+
function flowThroughPropertyNames() {
290+
var obj = {};
291+
obj[Math.random()] = window.name;
292+
for (var p in obj)
293+
$(p); // OK
294+
}

0 commit comments

Comments
 (0)