Skip to content

Commit 5727b2a

Browse files
author
Max Schaefer
committed
JavaScript: Properly handle value-preserving paths.
When constructing a path through a property write/read pair, we want to make sure that we only use value-preserving steps to track the base object. However, the value flowing in from the right-hand side of the assignment may have a different flow label (such as `taint()`), so we cannot use the normal `append` predicate to construct the composite path.
1 parent 910d6de commit 5727b2a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,7 @@ private predicate reachableFromStoreBase(string prop, DataFlow::Node rhs, DataFl
595595
exists (DataFlow::Node mid, PathSummary oldSummary, PathSummary newSummary |
596596
reachableFromStoreBase(prop, rhs, mid, cfg, oldSummary) and
597597
flowStep(mid, cfg, nd, newSummary) and
598-
newSummary.getEndLabel() = FlowLabel::data() and
599-
summary = oldSummary.append(newSummary)
598+
summary = oldSummary.appendValuePreserving(newSummary)
600599
)
601600
}
602601

javascript/ql/src/semmle/javascript/dataflow/internal/FlowSteps.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,22 @@ class PathSummary extends TPathSummary {
304304
)
305305
}
306306

307+
/**
308+
* Gets the summary for the path obtained by appending `that` to `this`, where
309+
* `that` must be a path mapping `data` to `data` (in other words, it must be
310+
* a value-preserving path).
311+
*/
312+
PathSummary appendValuePreserving(PathSummary that) {
313+
exists (Boolean hasReturn2, Boolean hasCall2 |
314+
that = MkPathSummary(hasReturn2, hasCall2, FlowLabel::data(), FlowLabel::data()) |
315+
result = MkPathSummary(hasReturn.booleanOr(hasReturn2),
316+
hasCall.booleanOr(hasCall2),
317+
start, end) and
318+
// avoid constructing invalid paths
319+
not (hasCall = true and hasReturn2 = true)
320+
)
321+
}
322+
307323
/**
308324
* Gets the summary for the path obtained by appending `this` to `that`.
309325
*/

javascript/ql/test/library-tests/InterProceduralFlow/TaintTracking.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class TestTaintTrackingConfiguration extends TaintTracking::Configuration {
3333

3434
from TestTaintTrackingConfiguration tttc, DataFlow::Node src, DataFlow::Node snk
3535
where tttc.hasFlow(src, snk)
36-
select src, snk
36+
select src, snk

0 commit comments

Comments
 (0)