Skip to content

Commit 0d3cf90

Browse files
committed
JS: Add tests for captured 'this' (genuine FN)
1 parent 09eddc9 commit 0d3cf90

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ legacyDataFlowDifference
77
| callbacks.js:44:17:44:24 | source() | callbacks.js:38:35:38:35 | x | only flow with NEW data flow library |
88
| capture-flow.js:89:13:89:20 | source() | capture-flow.js:89:6:89:21 | test3c(source()) | only flow with NEW data flow library |
99
| capture-flow.js:101:12:101:19 | source() | capture-flow.js:102:6:102:20 | test5("safe")() | only flow with OLD data flow library |
10+
| capture-flow.js:274:33:274:40 | source() | capture-flow.js:272:10:272:17 | this.foo | only flow with OLD data flow library |
11+
| capture-flow.js:274:33:274:40 | source() | capture-flow.js:274:6:274:45 | new Cap ... ()).foo | only flow with OLD data flow library |
12+
| capture-flow.js:283:34:283:41 | source() | capture-flow.js:284:6:284:44 | new Cap ... e').foo | only flow with NEW data flow library |
1013
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:40:8:40:14 | e.taint | only flow with NEW data flow library |
1114
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:44:8:44:19 | f_safe.taint | only flow with NEW data flow library |
1215
| constructor-calls.js:20:15:20:22 | source() | constructor-calls.js:39:8:39:14 | e.param | only flow with NEW data flow library |
@@ -113,6 +116,9 @@ flow
113116
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:248:18:248:27 | this.field |
114117
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:252:14:252:36 | objectW ... s.field |
115118
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:253:14:253:23 | this.field |
119+
| capture-flow.js:262:16:262:23 | source() | capture-flow.js:264:14:264:21 | this.foo |
120+
| capture-flow.js:283:34:283:41 | source() | capture-flow.js:283:6:283:46 | new Cap ... ()).foo |
121+
| capture-flow.js:283:34:283:41 | source() | capture-flow.js:284:6:284:44 | new Cap ... e').foo |
116122
| captured-sanitizer.js:25:3:25:10 | source() | captured-sanitizer.js:15:10:15:10 | x |
117123
| case.js:2:16:2:23 | source() | case.js:5:8:5:35 | changeC ... source) |
118124
| case.js:2:16:2:23 | source() | case.js:8:8:8:24 | camelCase(source) |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ legacyDataFlowDifference
99
| callbacks.js:44:17:44:24 | source() | callbacks.js:38:35:38:35 | x | only flow with NEW data flow library |
1010
| capture-flow.js:89:13:89:20 | source() | capture-flow.js:89:6:89:21 | test3c(source()) | only flow with NEW data flow library |
1111
| capture-flow.js:101:12:101:19 | source() | capture-flow.js:102:6:102:20 | test5("safe")() | only flow with OLD data flow library |
12+
| capture-flow.js:274:33:274:40 | source() | capture-flow.js:272:10:272:17 | this.foo | only flow with OLD data flow library |
13+
| capture-flow.js:274:33:274:40 | source() | capture-flow.js:274:6:274:45 | new Cap ... ()).foo | only flow with OLD data flow library |
1214
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:40:8:40:14 | e.taint | only flow with NEW data flow library |
1315
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:44:8:44:19 | f_safe.taint | only flow with NEW data flow library |
1416
| constructor-calls.js:20:15:20:22 | source() | constructor-calls.js:39:8:39:14 | e.param | only flow with NEW data flow library |
@@ -90,6 +92,8 @@ flow
9092
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:248:18:248:27 | this.field |
9193
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:252:14:252:36 | objectW ... s.field |
9294
| capture-flow.js:259:23:259:30 | source() | capture-flow.js:253:14:253:23 | this.field |
95+
| capture-flow.js:262:16:262:23 | source() | capture-flow.js:264:14:264:21 | this.foo |
96+
| capture-flow.js:283:34:283:41 | source() | capture-flow.js:283:6:283:46 | new Cap ... ()).foo |
9397
| captured-sanitizer.js:25:3:25:10 | source() | captured-sanitizer.js:15:10:15:10 | x |
9498
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:24:8:24:14 | c.taint |
9599
| constructor-calls.js:4:18:4:25 | source() | constructor-calls.js:28:8:28:19 | c_safe.taint |

javascript/ql/test/library-tests/TaintTracking/capture-flow.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,28 @@ function testObjectWithMethods(taint) {
257257
objectWithMethods.functionAddedLater();
258258
}
259259
testObjectWithMethods(source());
260+
261+
function captureThis() {
262+
this.foo = source();
263+
window.addEventListener('click', () => {
264+
sink(this.foo); // NOT OK
265+
});
266+
}
267+
268+
function CaptureThisWithoutJump(x) {
269+
[1].forEach(() => {
270+
this.foo = x;
271+
});
272+
sink(this.foo); // NOT OK [INCONSISTENCY]
273+
}
274+
sink(new CaptureThisWithoutJump(source()).foo); // NOT OK [INCONSISTENCY]
275+
sink(new CaptureThisWithoutJump('safe').foo); // OK
276+
277+
function CaptureThisWithoutJump2(x) {
278+
this.foo = x;
279+
let y;
280+
[1].forEach(() => y = this.foo);
281+
return y;
282+
}
283+
sink(new CaptureThisWithoutJump2(source()).foo); // NOT OK
284+
sink(new CaptureThisWithoutJump2('safe').foo); // OK [INCONSISTENCY]

0 commit comments

Comments
 (0)