15
15
16
16
import java
17
17
import semmle.code.java.dataflow.FlowSources
18
+ private import semmle.code.java.dataflow.ExternalFlow
18
19
import semmle.code.java.security.PathCreation
19
20
import DataFlow:: PathGraph
20
21
import TaintedPathCommon
@@ -25,20 +26,34 @@ class TaintedPathLocalConfig extends TaintTracking::Configuration {
25
26
override predicate isSource ( DataFlow:: Node source ) { source instanceof LocalUserInput }
26
27
27
28
override predicate isSink ( DataFlow:: Node sink ) {
28
- sink .asExpr ( ) = any ( PathCreation p ) .getAnInput ( )
29
+ (
30
+ sink .asExpr ( ) = any ( PathCreation p ) .getAnInput ( )
31
+ or
32
+ sinkNode ( sink , "create-file" )
33
+ ) and
34
+ not guarded ( sink .asExpr ( ) )
29
35
}
30
36
31
37
override predicate isAdditionalTaintStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
32
38
any ( TaintedPathAdditionalTaintStep s ) .step ( n1 , n2 )
33
39
}
34
40
}
35
41
36
- from
37
- DataFlow:: PathNode source , DataFlow:: PathNode sink , PathCreation p , Expr e ,
38
- TaintedPathLocalConfig conf
39
- where
40
- e = sink .getNode ( ) .asExpr ( ) and
41
- e = p .getAnInput ( ) and
42
- conf .hasFlowPath ( source , sink ) and
43
- not guarded ( e )
44
- select p , source , sink , "This path depends on a $@." , source .getNode ( ) , "user-provided value"
42
+ /**
43
+ * Gets the data-flow node at which to report a path ending at `sink`.
44
+ *
45
+ * Previously this query flagged alerts exclusively at `PathCreation` sites,
46
+ * so to avoid perturbing existing alerts, where a `PathCreation` exists we
47
+ * continue to report there; otherwise we report directly at `sink`.
48
+ */
49
+ DataFlow:: Node getReportingNode ( DataFlow:: Node sink ) {
50
+ any ( TaintedPathLocalConfig c ) .hasFlowTo ( sink ) and
51
+ if exists ( PathCreation pc | pc .getAnInput ( ) = sink .asExpr ( ) )
52
+ then result .asExpr ( ) = any ( PathCreation pc | pc .getAnInput ( ) = sink .asExpr ( ) )
53
+ else result = sink
54
+ }
55
+
56
+ from DataFlow:: PathNode source , DataFlow:: PathNode sink , TaintedPathLocalConfig conf
57
+ where conf .hasFlowPath ( source , sink )
58
+ select getReportingNode ( sink .getNode ( ) ) , source , sink , "This path depends on a $@." ,
59
+ source .getNode ( ) , "user-provided value"
0 commit comments