Skip to content

Commit 457ce14

Browse files
committed
JS: Summarize steps into captured variables
1 parent 093ff41 commit 457ce14

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,13 @@ private predicate flowThroughCall(
11831183
not cfg.isLabeledBarrier(output, summary.getEndLabel())
11841184
)
11851185
or
1186+
exists(Function f, LocalVariable variable |
1187+
reachableFromInput(f, _, input, output, cfg, summary) and
1188+
output = DataFlow::capturedVariableNode(variable) and
1189+
getCapturedVariableDepth(variable) < getContainerDepth(f) and // Only step outwards
1190+
not cfg.isLabeledBarrier(output, summary.getEndLabel())
1191+
)
1192+
or
11861193
exists(Function f, DataFlow::Node invk, DataFlow::Node ret |
11871194
DataFlow::exceptionalFunctionReturnNode(ret, f) and
11881195
DataFlow::exceptionalInvocationReturnNode(output, invk.asExpr()) and

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ DataFlow::Node getThrowTarget(DataFlow::Node thrower) {
109109
*/
110110
cached
111111
private module CachedSteps {
112+
/** Gets the nesting depth of the given container, starting with the top-level at 0. */
113+
cached
114+
int getContainerDepth(StmtContainer container) {
115+
not exists(container.getEnclosingContainer()) and
116+
result = 0
117+
or
118+
result = 1 + getContainerDepth(container.getEnclosingContainer())
119+
}
120+
121+
/** Gets the nesting depth of the container declaring the given captured variable. */
122+
cached
123+
int getCapturedVariableDepth(LocalVariable v) {
124+
v.isCaptured() and
125+
result = getContainerDepth(v.getDeclaringContainer())
126+
}
127+
112128
/**
113129
* Holds if `f` captures the given `variable` in `cap`.
114130
*/

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ typeInferenceMismatch
3333
| callbacks.js:50:18:50:25 | source() | callbacks.js:30:29:30:29 | y |
3434
| callbacks.js:51:18:51:25 | source() | callbacks.js:30:29:30:29 | y |
3535
| callbacks.js:53:23:53:30 | source() | callbacks.js:58:10:58:10 | x |
36+
| capture-flow.js:9:11:9:18 | source() | capture-flow.js:14:10:14:16 | outer() |
37+
| capture-flow.js:9:11:9:18 | source() | capture-flow.js:19:6:19:16 | outerMost() |
3638
| capture-flow.js:31:14:31:21 | source() | capture-flow.js:31:6:31:22 | confuse(source()) |
3739
| captured-sanitizer.js:25:3:25:10 | source() | captured-sanitizer.js:15:10:15:10 | x |
3840
| closure.js:6:15:6:22 | source() | closure.js:8:8:8:31 | string. ... (taint) |

javascript/ql/test/library-tests/TaintTracking/DataFlowTracking.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
| callbacks.js:50:18:50:25 | source() | callbacks.js:30:29:30:29 | y |
2424
| callbacks.js:51:18:51:25 | source() | callbacks.js:30:29:30:29 | y |
2525
| callbacks.js:53:23:53:30 | source() | callbacks.js:58:10:58:10 | x |
26+
| capture-flow.js:9:11:9:18 | source() | capture-flow.js:14:10:14:16 | outer() |
27+
| capture-flow.js:9:11:9:18 | source() | capture-flow.js:19:6:19:16 | outerMost() |
2628
| capture-flow.js:31:14:31:21 | source() | capture-flow.js:31:6:31:22 | confuse(source()) |
2729
| captured-sanitizer.js:25:3:25:10 | source() | captured-sanitizer.js:15:10:15:10 | x |
2830
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:18:8:18:14 | c.taint |

0 commit comments

Comments
 (0)