@@ -3,12 +3,18 @@ private import semmle.code.java.dataflow.DataFlow
3
3
private import semmle.code.java.dataflow.FlowSteps
4
4
5
5
/** A reference type that extends a parameterization the Promise type. */
6
- class RatpackPromise extends RefType {
6
+ private class RatpackPromise extends RefType {
7
7
RatpackPromise ( ) {
8
8
getSourceDeclaration ( ) .getASourceSupertype * ( ) .hasQualifiedName ( "ratpack.exec" , "Promise" )
9
9
}
10
10
}
11
11
12
+ private class RatpackPromiseValueMethod extends Method , TaintPreservingCallable {
13
+ RatpackPromiseValueMethod ( ) { isStatic ( ) and hasName ( "value" ) }
14
+
15
+ override predicate returnsTaintFrom ( int arg ) { arg = 0 }
16
+ }
17
+
12
18
abstract private class SimpleFluentLambdaMethod extends Method {
13
19
SimpleFluentLambdaMethod ( ) { getNumberOfParameters ( ) = 1 }
14
20
@@ -25,18 +31,18 @@ abstract private class SimpleFluentLambdaMethod extends Method {
25
31
predicate doesReturnTaint ( ) { none ( ) }
26
32
}
27
33
28
- class RatpackPromiseMapMethod extends SimpleFluentLambdaMethod {
34
+ private class RatpackPromiseMapMethod extends SimpleFluentLambdaMethod {
29
35
RatpackPromiseMapMethod ( ) {
30
36
getDeclaringType ( ) instanceof RatpackPromise and
31
- hasName ( "map" )
37
+ hasName ( [ "map" , "flatMap" ] )
32
38
}
33
39
34
40
override predicate consumesTaint ( int arg ) { arg = 0 }
35
41
36
42
override predicate doesReturnTaint ( ) { any ( ) }
37
43
}
38
44
39
- class RatpackPromiseThenMethod extends SimpleFluentLambdaMethod {
45
+ private class RatpackPromiseThenMethod extends SimpleFluentLambdaMethod {
40
46
RatpackPromiseThenMethod ( ) {
41
47
getDeclaringType ( ) instanceof RatpackPromise and
42
48
hasName ( "then" )
@@ -45,7 +51,7 @@ class RatpackPromiseThenMethod extends SimpleFluentLambdaMethod {
45
51
override predicate consumesTaint ( int arg ) { arg = 0 }
46
52
}
47
53
48
- class RatpackPromiseNextMethod extends FluentMethod , SimpleFluentLambdaMethod {
54
+ private class RatpackPromiseNextMethod extends FluentMethod , SimpleFluentLambdaMethod {
49
55
RatpackPromiseNextMethod ( ) {
50
56
getDeclaringType ( ) instanceof RatpackPromise and
51
57
hasName ( "next" )
@@ -54,21 +60,27 @@ class RatpackPromiseNextMethod extends FluentMethod, SimpleFluentLambdaMethod {
54
60
override predicate consumesTaint ( int arg ) { arg = 0 }
55
61
}
56
62
57
- private class RatpackPromiseTaintPreservingCallable extends AdditionalTaintStep {
63
+ private class RatpackPromiseTaintPreservingStep extends AdditionalTaintStep {
58
64
override predicate step ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
59
65
stepIntoLambda ( node1 , node2 ) or
60
66
stepOutOfLambda ( node1 , node2 )
61
67
}
62
68
69
+ /**
70
+ * Holds if the method access qualifier `node1` has dataflow to the functional expression parameter `node2`.
71
+ */
63
72
predicate stepIntoLambda ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
64
- exists ( MethodAccess ma , SimpleFluentLambdaMethod sflm , int arg |
73
+ exists ( MethodAccess ma , SimpleFluentLambdaMethod sflm , int arg | sflm . consumesTaint ( arg ) |
65
74
ma .getMethod ( ) = sflm and
66
- sflm .consumesTaint ( arg ) and
67
75
node1 .asExpr ( ) = ma .getQualifier ( ) and
68
76
ma .getArgument ( 0 ) .( FunctionalExpr ) .asMethod ( ) .getParameter ( arg ) = node2 .asParameter ( )
69
77
)
70
78
}
71
79
80
+ /**
81
+ * Holds if the return statement result of the functional expression `node1` has dataflow to the
82
+ * method access result `node2`.
83
+ */
72
84
predicate stepOutOfLambda ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
73
85
exists ( SimpleFluentLambdaMethod sflm , MethodAccess ma , FunctionalExpr fe |
74
86
sflm .doesReturnTaint ( )
0 commit comments