@@ -14,23 +14,11 @@ private import semmle.code.java.Expr as Expr
14
14
private import semmle.code.java.security.QueryInjection
15
15
private import semmle.code.java.security.RequestForgery
16
16
private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclusions
17
+ private import AutomodelJavaUtil as AutomodelJavaUtil
18
+ private import AutomodelSharedGetCallable as AutomodelSharedGetCallable
17
19
import AutomodelSharedCharacteristics as SharedCharacteristics
18
20
import AutomodelEndpointTypes as AutomodelEndpointTypes
19
21
20
- /**
21
- * A meta data extractor. Any Java extraction mode needs to implement exactly
22
- * one instance of this class.
23
- */
24
- abstract class MetadataExtractor extends string {
25
- bindingset [ this ]
26
- MetadataExtractor ( ) { any ( ) }
27
-
28
- abstract predicate hasMetadata (
29
- DataFlow:: ParameterNode e , string package , string type , boolean subtypes , string name ,
30
- string signature , int input , string parameterName
31
- ) ;
32
- }
33
-
34
22
newtype JavaRelatedLocationType =
35
23
MethodDoc ( ) or
36
24
ClassDoc ( )
@@ -60,31 +48,7 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
60
48
61
49
RelatedLocation asLocation ( Endpoint e ) { result = e .asParameter ( ) }
62
50
63
- predicate isKnownKind ( string kind , string humanReadableKind , EndpointType type ) {
64
- kind = "read-file" and
65
- humanReadableKind = "read file" and
66
- type instanceof AutomodelEndpointTypes:: TaintedPathSinkType
67
- or
68
- kind = "create-file" and
69
- humanReadableKind = "create file" and
70
- type instanceof AutomodelEndpointTypes:: TaintedPathSinkType
71
- or
72
- kind = "sql" and
73
- humanReadableKind = "mad modeled sql" and
74
- type instanceof AutomodelEndpointTypes:: SqlSinkType
75
- or
76
- kind = "open-url" and
77
- humanReadableKind = "open url" and
78
- type instanceof AutomodelEndpointTypes:: RequestForgerySinkType
79
- or
80
- kind = "jdbc-url" and
81
- humanReadableKind = "jdbc url" and
82
- type instanceof AutomodelEndpointTypes:: RequestForgerySinkType
83
- or
84
- kind = "command-injection" and
85
- humanReadableKind = "command injection" and
86
- type instanceof AutomodelEndpointTypes:: CommandInjectionSinkType
87
- }
51
+ predicate isKnownKind = AutomodelJavaUtil:: isKnownKind / 3 ;
88
52
89
53
predicate isSink ( Endpoint e , string kind ) {
90
54
exists ( string package , string type , string name , string signature , string ext , string input |
@@ -103,33 +67,41 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
103
67
additional predicate sinkSpec (
104
68
Endpoint e , string package , string type , string name , string signature , string ext , string input
105
69
) {
106
- FrameworkCandidatesImpl :: getCallable ( e ) .hasQualifiedName ( package , type , name ) and
107
- signature = ExternalFlow:: paramsString ( getCallable ( e ) ) and
70
+ FrameworkModeGetCallable :: getCallable ( e ) .hasQualifiedName ( package , type , name ) and
71
+ signature = ExternalFlow:: paramsString ( FrameworkModeGetCallable :: getCallable ( e ) ) and
108
72
ext = "" and
109
73
exists ( int paramIdx | e .isParameterOf ( _, paramIdx ) |
110
- if paramIdx = - 1 then input = "Argument[this]" else input = "Argument[" + paramIdx + "]"
74
+ input = AutomodelJavaUtil :: getArgumentForIndex ( paramIdx )
111
75
)
112
76
}
113
77
114
78
/**
115
- * Returns the related location for the given endpoint.
79
+ * Gets the related location for the given endpoint.
116
80
*
117
81
* Related locations can be JavaDoc comments of the class or the method.
118
82
*/
119
83
RelatedLocation getRelatedLocation ( Endpoint e , RelatedLocationType type ) {
120
84
type = MethodDoc ( ) and
121
- result = FrameworkCandidatesImpl :: getCallable ( e ) .( Documentable ) .getJavadoc ( )
85
+ result = FrameworkModeGetCallable :: getCallable ( e ) .( Documentable ) .getJavadoc ( )
122
86
or
123
87
type = ClassDoc ( ) and
124
- result = FrameworkCandidatesImpl :: getCallable ( e ) .getDeclaringType ( ) .( Documentable ) .getJavadoc ( )
88
+ result = FrameworkModeGetCallable :: getCallable ( e ) .getDeclaringType ( ) .( Documentable ) .getJavadoc ( )
125
89
}
90
+ }
91
+
92
+ private class JavaCallable = Callable ;
93
+
94
+ private module FrameworkModeGetCallable implements AutomodelSharedGetCallable:: GetCallableSig {
95
+ class Callable = JavaCallable ;
96
+
97
+ class Endpoint = FrameworkCandidatesImpl:: Endpoint ;
126
98
127
99
/**
128
100
* Returns the callable that contains the given endpoint.
129
101
*
130
102
* Each Java mode should implement this predicate.
131
103
*/
132
- additional Callable getCallable ( Endpoint e ) { result = e .getEnclosingCallable ( ) }
104
+ Callable getCallable ( Endpoint e ) { result = e .getEnclosingCallable ( ) }
133
105
}
134
106
135
107
module CharacteristicsImpl = SharedCharacteristics:: SharedCharacteristics< FrameworkCandidatesImpl > ;
@@ -145,35 +117,19 @@ class Endpoint = FrameworkCandidatesImpl::Endpoint;
145
117
/**
146
118
* A MetadataExtractor that extracts metadata for framework mode.
147
119
*/
148
- class FrameworkModeMetadataExtractor extends MetadataExtractor {
120
+ class FrameworkModeMetadataExtractor extends string {
149
121
FrameworkModeMetadataExtractor ( ) { this = "FrameworkModeMetadataExtractor" }
150
122
151
- /**
152
- * By convention, the subtypes property of the MaD declaration should only be
153
- * true when there _can_ exist any subtypes with a different implementation.
154
- *
155
- * It would technically be ok to always use the value 'true', but this would
156
- * break convention.
157
- */
158
- boolean considerSubtypes ( Callable callable ) {
159
- if
160
- callable .isStatic ( ) or
161
- callable .getDeclaringType ( ) .isStatic ( ) or
162
- callable .isFinal ( ) or
163
- callable .getDeclaringType ( ) .isFinal ( )
164
- then result = false
165
- else result = true
166
- }
167
-
168
- override predicate hasMetadata (
169
- Endpoint e , string package , string type , boolean subtypes , string name , string signature ,
170
- int input , string parameterName
123
+ predicate hasMetadata (
124
+ Endpoint e , string package , string type , string subtypes , string name , string signature ,
125
+ string input , string parameterName
171
126
) {
172
- exists ( Callable callable |
173
- e .asParameter ( ) = callable .getParameter ( input ) and
127
+ exists ( Callable callable , int paramIdx |
128
+ e .asParameter ( ) = callable .getParameter ( paramIdx ) and
129
+ input = AutomodelJavaUtil:: getArgumentForIndex ( paramIdx ) and
174
130
package = callable .getDeclaringType ( ) .getPackage ( ) .getName ( ) and
175
131
type = callable .getDeclaringType ( ) .getErasure ( ) .( RefType ) .nestedName ( ) and
176
- subtypes = this . considerSubtypes ( callable ) and
132
+ subtypes = AutomodelJavaUtil :: considerSubtypes ( callable ) . toString ( ) and
177
133
name = callable .getName ( ) and
178
134
parameterName = e .asParameter ( ) .getName ( ) and
179
135
signature = ExternalFlow:: paramsString ( callable )
@@ -199,8 +155,8 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
199
155
200
156
override predicate appliesToEndpoint ( Endpoint e ) {
201
157
not FrameworkCandidatesImpl:: isSink ( e , _) and
202
- FrameworkCandidatesImpl :: getCallable ( e ) .getName ( ) .matches ( "is%" ) and
203
- FrameworkCandidatesImpl :: getCallable ( e ) .getReturnType ( ) instanceof BooleanType
158
+ FrameworkModeGetCallable :: getCallable ( e ) .getName ( ) .matches ( "is%" ) and
159
+ FrameworkModeGetCallable :: getCallable ( e ) .getReturnType ( ) instanceof BooleanType
204
160
}
205
161
}
206
162
@@ -218,7 +174,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
218
174
override predicate appliesToEndpoint ( Endpoint e ) {
219
175
not FrameworkCandidatesImpl:: isSink ( e , _) and
220
176
exists ( Callable callable |
221
- callable = FrameworkCandidatesImpl :: getCallable ( e ) and
177
+ callable = FrameworkModeGetCallable :: getCallable ( e ) and
222
178
callable .getName ( ) .toLowerCase ( ) = [ "exists" , "notexists" ] and
223
179
callable .getReturnType ( ) instanceof BooleanType
224
180
)
@@ -232,7 +188,7 @@ private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkChara
232
188
ExceptionCharacteristic ( ) { this = "exception" }
233
189
234
190
override predicate appliesToEndpoint ( Endpoint e ) {
235
- FrameworkCandidatesImpl :: getCallable ( e ) .getDeclaringType ( ) .getASupertype * ( ) instanceof
191
+ FrameworkModeGetCallable :: getCallable ( e ) .getDeclaringType ( ) .getASupertype * ( ) instanceof
236
192
TypeThrowable
237
193
}
238
194
}
@@ -258,7 +214,7 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
258
214
NonPublicMethodCharacteristic ( ) { this = "non-public method" }
259
215
260
216
override predicate appliesToEndpoint ( Endpoint e ) {
261
- not FrameworkCandidatesImpl :: getCallable ( e ) .isPublic ( )
217
+ not FrameworkModeGetCallable :: getCallable ( e ) .isPublic ( )
262
218
}
263
219
}
264
220
0 commit comments