@@ -15,7 +15,7 @@ import java
15
15
import experimental.semmle.code.java.security.SpringUrlRedirect
16
16
import semmle.code.java.dataflow.FlowSources
17
17
import semmle.code.java.controlflow.Guards
18
- import DataFlow :: PathGraph
18
+ import SpringUrlRedirectFlow :: PathGraph
19
19
20
20
private predicate startsWithSanitizer ( Guard g , Expr e , boolean branch ) {
21
21
g .( MethodAccess ) .getMethod ( ) .hasName ( "startsWith" ) and
@@ -25,18 +25,16 @@ private predicate startsWithSanitizer(Guard g, Expr e, boolean branch) {
25
25
branch = true
26
26
}
27
27
28
- class SpringUrlRedirectFlowConfig extends TaintTracking :: Configuration {
29
- SpringUrlRedirectFlowConfig ( ) { this = "SpringUrlRedirectFlowConfig" }
28
+ module SpringUrlRedirectFlowConfig implements DataFlow :: ConfigSig {
29
+ predicate isSource ( DataFlow :: Node source ) { source instanceof RemoteFlowSource }
30
30
31
- override predicate isSource ( DataFlow:: Node source ) { source instanceof RemoteFlowSource }
31
+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof SpringUrlRedirectSink }
32
32
33
- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof SpringUrlRedirectSink }
34
-
35
- override predicate isAdditionalTaintStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
33
+ predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
36
34
springUrlRedirectTaintStep ( fromNode , toNode )
37
35
}
38
36
39
- override predicate isSanitizer ( DataFlow:: Node node ) {
37
+ predicate isBarrier ( DataFlow:: Node node ) {
40
38
// Exclude the case where the left side of the concatenated string is not `redirect:`.
41
39
// E.g: `String url = "/path?token=" + request.getParameter("token");`
42
40
// Note this is quite a broad sanitizer (it will also sanitize the right-hand side of `url = "http://" + request.getParameter("token")`);
@@ -62,7 +60,9 @@ class SpringUrlRedirectFlowConfig extends TaintTracking::Configuration {
62
60
}
63
61
}
64
62
65
- from DataFlow:: PathNode source , DataFlow:: PathNode sink , SpringUrlRedirectFlowConfig conf
66
- where conf .hasFlowPath ( source , sink )
63
+ module SpringUrlRedirectFlow = TaintTracking:: Global< SpringUrlRedirectFlowConfig > ;
64
+
65
+ from SpringUrlRedirectFlow:: PathNode source , SpringUrlRedirectFlow:: PathNode sink
66
+ where SpringUrlRedirectFlow:: flowPath ( source , sink )
67
67
select sink .getNode ( ) , source , sink , "Potentially untrusted URL redirection due to $@." ,
68
68
source .getNode ( ) , "user-provided value"
0 commit comments