Skip to content

Commit

Permalink
JS: Add: taint step test cases for findLastIndex, findLast, find
Browse files Browse the repository at this point in the history
  • Loading branch information
Napalys committed Nov 19, 2024
1 parent c03d69a commit f1e95a8
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 137 deletions.
5 changes: 4 additions & 1 deletion javascript/ql/test/library-tests/Arrays/DataFlow.ql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import javascript
class ArrayFlowConfig extends DataFlow::Configuration {
ArrayFlowConfig() { this = "ArrayFlowConfig" }

override predicate isSource(DataFlow::Node source) { source.asExpr().getStringValue() = "source" }
override predicate isSource(DataFlow::Node source) {
source.asExpr().getStringValue() = "source" or
source.(DataFlow::CallNode).getCalleeName() = "source"
}

override predicate isSink(DataFlow::Node sink) {
sink = any(DataFlow::CallNode call | call.getCalleeName() = "sink").getAnArgument()
Expand Down
2 changes: 2 additions & 0 deletions javascript/ql/test/library-tests/Arrays/TaintFlow.expected
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
| arrays.js:120:19:120:26 | "source" | arrays.js:121:46:121:49 | item |
| arrays.js:120:19:120:26 | "source" | arrays.js:122:10:122:16 | element |
| arrays.js:126:19:126:26 | "source" | arrays.js:127:55:127:58 | item |
| arrays.js:131:17:131:24 | source() | arrays.js:133:10:133:17 | element1 |
| arrays.js:137:17:137:24 | source() | arrays.js:139:10:139:17 | element1 |
5 changes: 4 additions & 1 deletion javascript/ql/test/library-tests/Arrays/TaintFlow.ql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import javascript
class ArrayTaintFlowConfig extends TaintTracking::Configuration {
ArrayTaintFlowConfig() { this = "ArrayTaintFlowConfig" }

override predicate isSource(DataFlow::Node source) { source.asExpr().getStringValue() = "source" }
override predicate isSource(DataFlow::Node source) {
source.asExpr().getStringValue() = "source" or
source.(DataFlow::CallNode).getCalleeName() = "source"
}

override predicate isSink(DataFlow::Node sink) {
sink = any(DataFlow::CallNode call | call.getCalleeName() = "sink").getAnArgument()
Expand Down
17 changes: 17 additions & 0 deletions javascript/ql/test/library-tests/Arrays/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,21 @@
const element = list.findLastIndex((item) => sink(item)); // NOT OK
sink(element); // OK
}
{
const arr = source();
const element1 = arr.find((item) => sink(item)); // NOT OK - only found with taint-tracking.
sink(element1); // NOT OK
}

{
const arr = source();
const element1 = arr.findLast((item) => sink(item)); // NOT OK - only found with taint-tracking.
sink(element1); // NOT OK
}

{
const arr = source();
const element1 = arr.findLastIndex((item) => sink(item)); // NOT OK - only found with taint-tracking.
sink(element1); // OK
}
});
Loading

0 comments on commit f1e95a8

Please sign in to comment.