@@ -12,7 +12,6 @@ private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummary
1212private import semmle.code.java.security.ExternalAPIs as ExternalAPIs
1313private import semmle.code.java.Expr as Expr
1414private import semmle.code.java.security.QueryInjection
15- private import semmle.code.java.security.RequestForgery
1615private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclusions
1716private import AutomodelJavaUtil as AutomodelJavaUtil
1817private import semmle.code.java.security.PathSanitizer as PathSanitizer
@@ -26,7 +25,17 @@ newtype JavaRelatedLocationType = CallContext()
2625 * A class representing nodes that are arguments to calls.
2726 */
2827private 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 }
3039}
3140
3241/**
@@ -67,19 +76,19 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
6776
6877 predicate isKnownKind = AutomodelJavaUtil:: isKnownKind / 2 ;
6978
70- predicate isSink ( Endpoint e , string kind ) {
79+ predicate isSink ( Endpoint e , string kind , string provenance ) {
7180 exists ( string package , string type , string name , string signature , string ext , string input |
7281 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 )
7483 )
7584 or
76- isCustomSink ( e , kind )
85+ isCustomSink ( e , kind ) and provenance = "custom-sink"
7786 }
7887
7988 predicate isNeutral ( Endpoint e ) {
8089 exists ( string package , string type , string name , string signature |
8190 sinkSpec ( e , package , type , name , signature , _, _) and
82- ExternalFlow:: neutralModel ( package , type , name , [ signature , "" ] , "sink" , _)
91+ ExternalFlow:: neutralModel ( package , type , name , [ signature , "" ] , _ , _)
8392 )
8493 }
8594
@@ -136,10 +145,6 @@ private module ApplicationModeGetCallable implements AutomodelSharedGetCallable:
136145 * should be empty.
137146 */
138147private 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
143148 e instanceof QueryInjectionSink and kind = "sql"
144149}
145150
@@ -200,7 +205,7 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
200205 UnexploitableIsCharacteristic ( ) { this = "unexploitable (is-style boolean method)" }
201206
202207 override predicate appliesToEndpoint ( Endpoint e ) {
203- not ApplicationCandidatesImpl:: isSink ( e , _) and
208+ not ApplicationCandidatesImpl:: isSink ( e , _, _ ) and
204209 ApplicationModeGetCallable:: getCallable ( e ) .getName ( ) .matches ( "is%" ) and
205210 ApplicationModeGetCallable:: getCallable ( e ) .getReturnType ( ) instanceof BooleanType
206211 }
@@ -218,7 +223,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
218223 UnexploitableExistsCharacteristic ( ) { this = "unexploitable (existence-checking boolean method)" }
219224
220225 override predicate appliesToEndpoint ( Endpoint e ) {
221- not ApplicationCandidatesImpl:: isSink ( e , _) and
226+ not ApplicationCandidatesImpl:: isSink ( e , _, _ ) and
222227 exists ( Callable callable |
223228 callable = ApplicationModeGetCallable:: getCallable ( e ) and
224229 callable .getName ( ) .toLowerCase ( ) = [ "exists" , "notexists" ] and
@@ -313,7 +318,8 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
313318
314319/**
315320 * 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.
317323 *
318324 * WARNING: These endpoints should not be used as negative samples for training, because some sinks may have been missed
319325 * 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
324330private class OtherArgumentToModeledMethodCharacteristic extends CharacteristicsImpl:: LikelyNotASinkCharacteristic
325331{
326332 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 "
328334 }
329335
330336 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
335341 e != otherSink
336342 )
337343 }
0 commit comments