Skip to content

Commit 28ead40

Browse files
committed
JS: Add: taint step to handle propagation of data flow from the array to callback
1 parent f1e95a8 commit 28ead40

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

javascript/ql/lib/semmle/javascript/Arrays.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,20 @@ private module ArrayLibraries {
492492
exists(DataFlow::MethodCallNode call |
493493
call.getMethodName() = ["findLast", "find", "findLastIndex"] and
494494
prop = arrayLikeElement() and
495-
obj = call.getReceiver() and
495+
obj = call.getReceiver().getALocalSource() and
496+
element = call.getCallback(0).getParameter(0)
497+
)
498+
}
499+
}
500+
501+
/**
502+
* This step models the propagation of data from the array to the callback function's parameter.
503+
*/
504+
private class ArrayCallBackDataTaintStep extends TaintTracking::SharedTaintStep {
505+
override predicate step(DataFlow::Node obj, DataFlow::Node element) {
506+
exists(DataFlow::MethodCallNode call |
507+
call.getMethodName() = ["findLast", "find", "findLastIndex"] and
508+
obj = call.getReceiver().getALocalSource() and
496509
element = call.getCallback(0).getParameter(0)
497510
)
498511
}

javascript/ql/test/library-tests/Arrays/TaintFlow.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
| arrays.js:120:19:120:26 | "source" | arrays.js:121:46:121:49 | item |
3636
| arrays.js:120:19:120:26 | "source" | arrays.js:122:10:122:16 | element |
3737
| arrays.js:126:19:126:26 | "source" | arrays.js:127:55:127:58 | item |
38+
| arrays.js:131:17:131:24 | source() | arrays.js:132:46:132:49 | item |
3839
| arrays.js:131:17:131:24 | source() | arrays.js:133:10:133:17 | element1 |
40+
| arrays.js:137:17:137:24 | source() | arrays.js:138:50:138:53 | item |
3941
| arrays.js:137:17:137:24 | source() | arrays.js:139:10:139:17 | element1 |
42+
| arrays.js:143:17:143:24 | source() | arrays.js:144:55:144:58 | item |

javascript/ql/test/library-tests/Arrays/arrays.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@
129129
}
130130
{
131131
const arr = source();
132-
const element1 = arr.find((item) => sink(item)); // NOT OK - only found with taint-tracking.
132+
const element1 = arr.find((item) => sink(item)); // NOT OK
133133
sink(element1); // NOT OK
134134
}
135135

136136
{
137137
const arr = source();
138-
const element1 = arr.findLast((item) => sink(item)); // NOT OK - only found with taint-tracking.
138+
const element1 = arr.findLast((item) => sink(item)); // NOT OK
139139
sink(element1); // NOT OK
140140
}
141141

142142
{
143143
const arr = source();
144-
const element1 = arr.findLastIndex((item) => sink(item)); // NOT OK - only found with taint-tracking.
144+
const element1 = arr.findLastIndex((item) => sink(item)); // NOT OK
145145
sink(element1); // OK
146146
}
147147
});

0 commit comments

Comments
 (0)