@@ -41,10 +41,12 @@ abstract class UrlForwardBarrier extends DataFlow::Node { }
41
41
42
42
private class PrimitiveBarrier extends UrlForwardBarrier instanceof SimpleTypeSanitizer { }
43
43
44
+ // TODO: QLDoc
44
45
private class FollowsBarrierPrefix extends UrlForwardBarrier {
45
46
FollowsBarrierPrefix ( ) { this .asExpr ( ) = any ( BarrierPrefix fp ) .getAnAppendedExpression ( ) }
46
47
}
47
48
49
+ // TODO: QLDoc and fix broadness of this prefix check...
48
50
private class BarrierPrefix extends InterestingPrefix {
49
51
BarrierPrefix ( ) {
50
52
not this .getStringValue ( ) .matches ( "/WEB-INF/%" ) and
@@ -54,6 +56,7 @@ private class BarrierPrefix extends InterestingPrefix {
54
56
override int getOffset ( ) { result = 0 }
55
57
}
56
58
59
+ /** A barrier that protects against path injection vulnerabilities while accounting for URL encoding. */
57
60
private class UrlPathBarrier extends UrlForwardBarrier instanceof PathInjectionSanitizer {
58
61
UrlPathBarrier ( ) {
59
62
this instanceof ExactPathMatchSanitizer
@@ -77,11 +80,8 @@ private class DefaultUrlDecodeCall extends UrlDecodeCall {
77
80
/** A repeated call to a method that decodes a URL. */
78
81
abstract class RepeatedUrlDecodeCall extends MethodCall { }
79
82
80
- private class DefaultRepeatedUrlDecodeCall extends RepeatedUrlDecodeCall {
81
- DefaultRepeatedUrlDecodeCall ( ) {
82
- this instanceof UrlDecodeCall and
83
- this .getAnEnclosingStmt ( ) instanceof LoopStmt
84
- }
83
+ private class DefaultRepeatedUrlDecodeCall extends RepeatedUrlDecodeCall instanceof UrlDecodeCall {
84
+ DefaultRepeatedUrlDecodeCall ( ) { this .getAnEnclosingStmt ( ) instanceof LoopStmt }
85
85
}
86
86
87
87
/** A method call that checks a string for URL encoding. */
@@ -94,17 +94,19 @@ private class DefaultCheckUrlEncodingCall extends CheckUrlEncodingCall {
94
94
}
95
95
}
96
96
97
+ /** A guard that looks for a method call that checks for URL encoding. */
97
98
private class CheckUrlEncodingGuard extends Guard instanceof CheckUrlEncodingCall {
98
99
Expr getCheckedExpr ( ) { result = this .( MethodCall ) .getQualifier ( ) }
99
100
}
100
101
102
+ /** Holds if `g` is guard for a URL that does not contain URL encoding. */
101
103
private predicate noUrlEncodingGuard ( Guard g , Expr e , boolean branch ) {
102
104
g instanceof CheckUrlEncodingGuard and
103
105
e = g .( CheckUrlEncodingGuard ) .getCheckedExpr ( ) and
104
106
branch = false
105
107
or
106
108
branch = false and
107
- g .( Expr ) .getType ( ) instanceof BooleanType and // TODO: remove debugging comment: // AssignExpr
109
+ g .( Expr ) .getType ( ) instanceof BooleanType and
108
110
(
109
111
exists ( CheckUrlEncodingCall call , AssignExpr ae |
110
112
ae .getSource ( ) = call and
@@ -115,24 +117,25 @@ private predicate noUrlEncodingGuard(Guard g, Expr e, boolean branch) {
115
117
exists ( CheckUrlEncodingCall call , LocalVariableDeclExpr vde |
116
118
vde .getInitOrPatternSource ( ) = call and
117
119
e = call .getQualifier ( ) and
118
- g = vde .getAnAccess ( ) //and
119
- //vde.getVariable() = g
120
- // TODO: remove debugging comments above
120
+ g = vde .getAnAccess ( )
121
121
)
122
122
)
123
123
}
124
124
125
+ /** A barrier for URLs that do not contain URL encoding. */
125
126
private class NoUrlEncodingBarrier extends DataFlow:: Node {
126
127
NoUrlEncodingBarrier ( ) { this = DataFlow:: BarrierGuard< noUrlEncodingGuard / 3 > :: getABarrierNode ( ) }
127
128
}
128
129
130
+ /** Holds if `g` is guard for a URL that is fully decoded. */
129
131
private predicate fullyDecodesUrlGuard ( Expr e ) {
130
132
exists ( CheckUrlEncodingGuard g , RepeatedUrlDecodeCall decodeCall |
131
133
e = g .getCheckedExpr ( ) and
132
134
g .controls ( decodeCall .getBasicBlock ( ) , true )
133
135
)
134
136
}
135
137
138
+ /** A barrier for URLs that are fully decoded. */
136
139
private class FullyDecodesUrlBarrier extends DataFlow:: Node {
137
140
FullyDecodesUrlBarrier ( ) {
138
141
exists ( Variable v , Expr e | this .asExpr ( ) = v .getAnAccess ( ) |
0 commit comments