1515
1616import java
1717import semmle.code.java.dataflow.FlowSources
18+ private import semmle.code.java.dataflow.ExternalFlow
1819import semmle.code.java.security.PathCreation
1920import DataFlow:: PathGraph
2021import TaintedPathCommon
@@ -25,20 +26,34 @@ class TaintedPathLocalConfig extends TaintTracking::Configuration {
2526 override predicate isSource ( DataFlow:: Node source ) { source instanceof LocalUserInput }
2627
2728 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 ( ) )
2935 }
3036
3137 override predicate isAdditionalTaintStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
3238 any ( TaintedPathAdditionalTaintStep s ) .step ( n1 , n2 )
3339 }
3440}
3541
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