@@ -384,10 +384,10 @@ private module ArrayLibraries {
384
384
}
385
385
386
386
/**
387
- * Gets a call to `Array.prototype.find` or a polyfill implementing the same functionality.
387
+ * Gets a call to `Array.prototype.find` or `Array.prototype.findLast` or a polyfill implementing the same functionality.
388
388
*/
389
389
DataFlow:: CallNode arrayFindCall ( DataFlow:: Node array ) {
390
- result .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "find" and
390
+ result .( DataFlow:: MethodCallNode ) .getMethodName ( ) in [ "find" , "findLast" ] and
391
391
array = result .getReceiver ( )
392
392
or
393
393
result = DataFlow:: moduleImport ( [ "array.prototype.find" , "array-find" ] ) .getACall ( ) and
@@ -483,4 +483,31 @@ private module ArrayLibraries {
483
483
)
484
484
}
485
485
}
486
+
487
+ /**
488
+ * Defines a data flow step that tracks the flow of data through callback functions in arrays.
489
+ */
490
+ private class ArrayCallBackDataFlowStep extends PreCallGraphStep {
491
+ override predicate loadStep ( DataFlow:: Node obj , DataFlow:: Node element , string prop ) {
492
+ exists ( DataFlow:: MethodCallNode call |
493
+ call .getMethodName ( ) = [ "findLast" , "find" , "findLastIndex" ] and
494
+ prop = arrayLikeElement ( ) and
495
+ obj = call .getReceiver ( ) 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 ( ) and
509
+ element = call .getCallback ( 0 ) .getParameter ( 0 )
510
+ )
511
+ }
512
+ }
486
513
}
0 commit comments