@@ -12,7 +12,6 @@ private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummary
12
12
private import semmle.code.java.security.ExternalAPIs as ExternalAPIs
13
13
private import semmle.code.java.Expr as Expr
14
14
private import semmle.code.java.security.QueryInjection
15
- private import semmle.code.java.security.RequestForgery
16
15
private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclusions
17
16
private import AutomodelJavaUtil as AutomodelJavaUtil
18
17
private import semmle.code.java.security.PathSanitizer as PathSanitizer
@@ -26,7 +25,17 @@ newtype JavaRelatedLocationType = CallContext()
26
25
* A class representing nodes that are arguments to calls.
27
26
*/
28
27
private class ArgumentNode extends DataFlow:: Node {
29
- ArgumentNode ( ) { this .asExpr ( ) = [ any ( Call c ) .getAnArgument ( ) , any ( Call c ) .getQualifier ( ) ] }
28
+ Call c ;
29
+
30
+ ArgumentNode ( ) {
31
+ exists ( Argument arg | this .asExpr ( ) = arg and not arg .isVararg ( ) and c = arg .getCall ( ) )
32
+ or
33
+ this .( DataFlow:: ImplicitVarargsArray ) .getCall ( ) = c
34
+ or
35
+ this = DataFlow:: getInstanceArgument ( c )
36
+ }
37
+
38
+ Call getCall ( ) { result = c }
30
39
}
31
40
32
41
/**
@@ -67,19 +76,19 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
67
76
68
77
predicate isKnownKind = AutomodelJavaUtil:: isKnownKind / 2 ;
69
78
70
- predicate isSink ( Endpoint e , string kind ) {
79
+ predicate isSink ( Endpoint e , string kind , string provenance ) {
71
80
exists ( string package , string type , string name , string signature , string ext , string input |
72
81
sinkSpec ( e , package , type , name , signature , ext , input ) and
73
- ExternalFlow:: sinkModel ( package , type , _, name , [ signature , "" ] , ext , input , kind , _ )
82
+ ExternalFlow:: sinkModel ( package , type , _, name , [ signature , "" ] , ext , input , kind , provenance )
74
83
)
75
84
or
76
- isCustomSink ( e , kind )
85
+ isCustomSink ( e , kind ) and provenance = "custom-sink"
77
86
}
78
87
79
88
predicate isNeutral ( Endpoint e ) {
80
89
exists ( string package , string type , string name , string signature |
81
90
sinkSpec ( e , package , type , name , signature , _, _) and
82
- ExternalFlow:: neutralModel ( package , type , name , [ signature , "" ] , "sink" , _)
91
+ ExternalFlow:: neutralModel ( package , type , name , [ signature , "" ] , _ , _)
83
92
)
84
93
}
85
94
@@ -136,10 +145,6 @@ private module ApplicationModeGetCallable implements AutomodelSharedGetCallable:
136
145
* should be empty.
137
146
*/
138
147
private predicate isCustomSink ( Endpoint e , string kind ) {
139
- e .asExpr ( ) instanceof ArgumentToExec and kind = "command injection"
140
- or
141
- e instanceof RequestForgerySink and kind = "request forgery"
142
- or
143
148
e instanceof QueryInjectionSink and kind = "sql"
144
149
}
145
150
@@ -200,7 +205,7 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
200
205
UnexploitableIsCharacteristic ( ) { this = "unexploitable (is-style boolean method)" }
201
206
202
207
override predicate appliesToEndpoint ( Endpoint e ) {
203
- not ApplicationCandidatesImpl:: isSink ( e , _) and
208
+ not ApplicationCandidatesImpl:: isSink ( e , _, _ ) and
204
209
ApplicationModeGetCallable:: getCallable ( e ) .getName ( ) .matches ( "is%" ) and
205
210
ApplicationModeGetCallable:: getCallable ( e ) .getReturnType ( ) instanceof BooleanType
206
211
}
@@ -218,7 +223,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
218
223
UnexploitableExistsCharacteristic ( ) { this = "unexploitable (existence-checking boolean method)" }
219
224
220
225
override predicate appliesToEndpoint ( Endpoint e ) {
221
- not ApplicationCandidatesImpl:: isSink ( e , _) and
226
+ not ApplicationCandidatesImpl:: isSink ( e , _, _ ) and
222
227
exists ( Callable callable |
223
228
callable = ApplicationModeGetCallable:: getCallable ( e ) and
224
229
callable .getName ( ) .toLowerCase ( ) = [ "exists" , "notexists" ] and
@@ -313,7 +318,8 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
313
318
314
319
/**
315
320
* A negative characteristic that indicates that an endpoint is a non-sink argument to a method whose sinks have already
316
- * been modeled.
321
+ * been modeled _manually_. This is restricted to manual sinks only, because only during the manual process do we have
322
+ * the expectation that all sinks present in a method have been considered.
317
323
*
318
324
* WARNING: These endpoints should not be used as negative samples for training, because some sinks may have been missed
319
325
* when the method was modeled. Specifically, as we start using ATM to merge in new declarations, we can be less sure
@@ -324,14 +330,14 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
324
330
private class OtherArgumentToModeledMethodCharacteristic extends CharacteristicsImpl:: LikelyNotASinkCharacteristic
325
331
{
326
332
OtherArgumentToModeledMethodCharacteristic ( ) {
327
- this = "other argument to a method that has already been modeled"
333
+ this = "other argument to a method that has already been modeled manually "
328
334
}
329
335
330
336
override predicate appliesToEndpoint ( Endpoint e ) {
331
- not ApplicationCandidatesImpl:: isSink ( e , _) and
332
- exists ( DataFlow :: Node otherSink |
333
- ApplicationCandidatesImpl:: isSink ( otherSink , _) and
334
- e .asExpr ( ) = otherSink .asExpr ( ) . ( Argument ) . getCall ( ) . getAnArgument ( ) and
337
+ not ApplicationCandidatesImpl:: isSink ( e , _, _ ) and
338
+ exists ( Endpoint otherSink |
339
+ ApplicationCandidatesImpl:: isSink ( otherSink , _, "manual" ) and
340
+ e .getCall ( ) = otherSink .getCall ( ) and
335
341
e != otherSink
336
342
)
337
343
}
0 commit comments