@@ -41,29 +41,50 @@ abstract class UrlForwardBarrier extends DataFlow::Node { }
41
41
42
42
private class PrimitiveBarrier extends UrlForwardBarrier instanceof SimpleTypeSanitizer { }
43
43
44
- private class FollowsBarrierPrefix extends DataFlow:: Node {
44
+ /**
45
+ * A barrier for values appended to a "redirect:" prefix.
46
+ * These results are excluded because they should be handled
47
+ * by the `java/unvalidated-url-redirection` query instead.
48
+ */
49
+ private class RedirectPrefixBarrier extends UrlForwardBarrier {
50
+ RedirectPrefixBarrier ( ) { this .asExpr ( ) = any ( RedirectPrefix fp ) .getAnAppendedExpression ( ) }
51
+ }
52
+
53
+ private class RedirectPrefix extends InterestingPrefix {
54
+ RedirectPrefix ( ) { this .getStringValue ( ) = "redirect:" }
55
+
56
+ override int getOffset ( ) { result = 0 }
57
+ }
58
+
59
+ /**
60
+ * A value that is the result of prepending a string that prevents
61
+ * any value from controlling the path of a URL.
62
+ */
63
+ private class FollowsBarrierPrefix extends UrlForwardBarrier {
45
64
FollowsBarrierPrefix ( ) { this .asExpr ( ) = any ( BarrierPrefix fp ) .getAnAppendedExpression ( ) }
46
65
}
47
66
48
67
private class BarrierPrefix extends InterestingPrefix {
68
+ int offset ;
69
+
49
70
BarrierPrefix ( ) {
50
- not this .getStringValue ( ) .matches ( "/WEB-INF/%" ) and
51
- not this instanceof ForwardPrefix
71
+ // Matches strings that look like when prepended to untrusted input, they will restrict
72
+ // the path of a URL: for example, anything containing `?` or `#`.
73
+ exists ( this .getStringValue ( ) .regexpFind ( "[?#]" , 0 , offset ) )
52
74
}
53
75
54
- override int getOffset ( ) { result = 0 }
76
+ override int getOffset ( ) { result = offset }
55
77
}
56
78
57
79
/**
58
- * A barrier that protects against path injection vulnerabilities while accounting
59
- * for URL encoding and concatenated prefixes .
80
+ * A barrier that protects against path injection vulnerabilities
81
+ * while accounting for URL encoding.
60
82
*/
61
83
private class UrlPathBarrier extends UrlForwardBarrier instanceof PathInjectionSanitizer {
62
84
UrlPathBarrier ( ) {
63
85
this instanceof ExactPathMatchSanitizer or
64
86
this instanceof NoUrlEncodingBarrier or
65
- this instanceof FullyDecodesUrlBarrier or
66
- this instanceof FollowsBarrierPrefix
87
+ this instanceof FullyDecodesUrlBarrier
67
88
}
68
89
}
69
90
0 commit comments