@@ -17,7 +17,7 @@ import UnsafeReflectionLib
17
17
import semmle.code.java.dataflow.DataFlow
18
18
import semmle.code.java.dataflow.FlowSources
19
19
import semmle.code.java.controlflow.Guards
20
- import DataFlow :: PathGraph
20
+ import UnsafeReflectionFlow :: PathGraph
21
21
22
22
private predicate containsSanitizer ( Guard g , Expr e , boolean branch ) {
23
23
g .( MethodAccess ) .getMethod ( ) .hasName ( "contains" ) and
@@ -31,14 +31,12 @@ private predicate equalsSanitizer(Guard g, Expr e, boolean branch) {
31
31
branch = true
32
32
}
33
33
34
- class UnsafeReflectionConfig extends TaintTracking :: Configuration {
35
- UnsafeReflectionConfig ( ) { this = "UnsafeReflectionConfig" }
34
+ module UnsafeReflectionConfig implements DataFlow :: ConfigSig {
35
+ predicate isSource ( DataFlow :: Node source ) { source instanceof RemoteFlowSource }
36
36
37
- override predicate isSource ( DataFlow:: Node source ) { source instanceof RemoteFlowSource }
37
+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof UnsafeReflectionSink }
38
38
39
- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof UnsafeReflectionSink }
40
-
41
- override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
39
+ predicate isAdditionalFlowStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
42
40
// Argument -> return of Class.forName, ClassLoader.loadClass
43
41
exists ( ReflectiveClassIdentifierMethodAccess rcimac |
44
42
rcimac .getArgument ( 0 ) = pred .asExpr ( ) and rcimac = succ .asExpr ( )
@@ -75,23 +73,25 @@ class UnsafeReflectionConfig extends TaintTracking::Configuration {
75
73
)
76
74
}
77
75
78
- override predicate isSanitizer ( DataFlow:: Node node ) {
76
+ predicate isBarrier ( DataFlow:: Node node ) {
79
77
node = DataFlow:: BarrierGuard< containsSanitizer / 3 > :: getABarrierNode ( ) or
80
78
node = DataFlow:: BarrierGuard< equalsSanitizer / 3 > :: getABarrierNode ( )
81
79
}
82
80
}
83
81
82
+ module UnsafeReflectionFlow = TaintTracking:: Global< UnsafeReflectionConfig > ;
83
+
84
84
private Expr getAMethodArgument ( MethodAccess reflectiveCall ) {
85
85
result = reflectiveCall .( NewInstance ) .getAnArgument ( )
86
86
or
87
87
result = reflectiveCall .( MethodInvokeCall ) .getAnArgument ( )
88
88
}
89
89
90
90
from
91
- DataFlow :: PathNode source , DataFlow :: PathNode sink , UnsafeReflectionConfig conf ,
91
+ UnsafeReflectionFlow :: PathNode source , UnsafeReflectionFlow :: PathNode sink ,
92
92
MethodAccess reflectiveCall
93
93
where
94
- conf . hasFlowPath ( source , sink ) and
94
+ UnsafeReflectionFlow :: flowPath ( source , sink ) and
95
95
sink .getNode ( ) .asExpr ( ) = reflectiveCall .getQualifier ( ) and
96
- conf . hasFlowToExpr ( getAMethodArgument ( reflectiveCall ) )
96
+ UnsafeReflectionFlow :: flowToExpr ( getAMethodArgument ( reflectiveCall ) )
97
97
select sink .getNode ( ) , source , sink , "Unsafe reflection of $@." , source .getNode ( ) , "user input"
0 commit comments