@@ -12,6 +12,7 @@ private import DefUse
1212private import semmle.code.java.security.SecurityTests
1313private import semmle.code.java.security.Validation
1414private import semmle.code.java.frameworks.android.Intent
15+ private import semmle.code.java.Maps
1516
1617module TaintTracking {
1718 /**
@@ -209,6 +210,12 @@ module TaintTracking {
209210 sink = assign .getDest ( ) .( ArrayAccess ) .getArray ( )
210211 )
211212 or
213+ exists ( EnhancedForStmt for , SsaExplicitUpdate v |
214+ for .getExpr ( ) = src and
215+ v .getDefiningExpr ( ) = for .getVariable ( ) and
216+ v .getAFirstUse ( ) = sink
217+ )
218+ or
212219 constructorStep ( src , sink )
213220 or
214221 qualifierToMethodStep ( src , sink )
@@ -418,8 +425,49 @@ module TaintTracking {
418425 or
419426 m instanceof IntentGetExtraMethod
420427 or
421- m instanceof CollectionMethod and
422- m .hasName ( "toArray" )
428+ m
429+ .getDeclaringType ( )
430+ .getSourceDeclaration ( )
431+ .getASourceSupertype * ( )
432+ .hasQualifiedName ( "java.util" , "Map<>$Entry" ) and
433+ m .hasName ( "getValue" )
434+ or
435+ m
436+ .getDeclaringType ( )
437+ .getSourceDeclaration ( )
438+ .getASourceSupertype * ( )
439+ .hasQualifiedName ( "java.lang" , "Iterable" ) and
440+ m .hasName ( "iterator" )
441+ or
442+ m
443+ .getDeclaringType ( )
444+ .getSourceDeclaration ( )
445+ .getASourceSupertype * ( )
446+ .hasQualifiedName ( "java.util" , "Iterator" ) and
447+ m .hasName ( "next" )
448+ or
449+ m .getDeclaringType ( ) .getSourceDeclaration ( ) .hasQualifiedName ( "java.util" , "Enumeration" ) and
450+ m .hasName ( "nextElement" )
451+ or
452+ m .( MapMethod ) .hasName ( "entrySet" )
453+ or
454+ m .( MapMethod ) .hasName ( "get" )
455+ or
456+ m .( MapMethod ) .hasName ( "remove" )
457+ or
458+ m .( MapMethod ) .hasName ( "values" )
459+ or
460+ m .( CollectionMethod ) .hasName ( "toArray" )
461+ or
462+ m .( CollectionMethod ) .hasName ( "get" )
463+ or
464+ m .( CollectionMethod ) .hasName ( "remove" ) and m .getParameterType ( 0 ) .( PrimitiveType ) .hasName ( "int" )
465+ or
466+ m .( CollectionMethod ) .hasName ( "subList" )
467+ or
468+ m .( CollectionMethod ) .hasName ( "firstElement" )
469+ or
470+ m .( CollectionMethod ) .hasName ( "lastElement" )
423471 or
424472 m .getDeclaringType ( ) .hasQualifiedName ( "java.nio" , "ByteBuffer" ) and
425473 m .hasName ( "get" )
@@ -596,6 +644,18 @@ module TaintTracking {
596644 method .getDeclaringType ( ) .hasQualifiedName ( "java.io" , "ByteArrayOutputStream" ) and
597645 method .hasName ( "write" ) and
598646 arg = 0
647+ or
648+ method .( MapMethod ) .hasName ( "put" ) and arg = 1
649+ or
650+ method .( MapMethod ) .hasName ( "putAll" ) and arg = 0
651+ or
652+ method .( CollectionMethod ) .hasName ( "add" ) and arg = method .getNumberOfParameters ( ) - 1
653+ or
654+ method .( CollectionMethod ) .hasName ( "addAll" ) and arg = method .getNumberOfParameters ( ) - 1
655+ or
656+ method .( CollectionMethod ) .hasName ( "addElement" ) and arg = 0
657+ or
658+ method .( CollectionMethod ) .hasName ( "set" ) and arg = 1
599659 }
600660
601661 /** A comparison or equality test with a constant. */
0 commit comments