Skip to content

Commit a807596

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add QLDocs to UrlPathBarrier code
1 parent 042dcf9 commit a807596

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

java/ql/lib/semmle/code/java/security/UrlForward.qll

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ abstract class UrlForwardBarrier extends DataFlow::Node { }
4141

4242
private class PrimitiveBarrier extends UrlForwardBarrier instanceof SimpleTypeSanitizer { }
4343

44+
// TODO: QLDoc
4445
private class FollowsBarrierPrefix extends UrlForwardBarrier {
4546
FollowsBarrierPrefix() { this.asExpr() = any(BarrierPrefix fp).getAnAppendedExpression() }
4647
}
4748

49+
// TODO: QLDoc and fix broadness of this prefix check...
4850
private class BarrierPrefix extends InterestingPrefix {
4951
BarrierPrefix() {
5052
not this.getStringValue().matches("/WEB-INF/%") and
@@ -54,6 +56,7 @@ private class BarrierPrefix extends InterestingPrefix {
5456
override int getOffset() { result = 0 }
5557
}
5658

59+
/** A barrier that protects against path injection vulnerabilities while accounting for URL encoding. */
5760
private class UrlPathBarrier extends UrlForwardBarrier instanceof PathInjectionSanitizer {
5861
UrlPathBarrier() {
5962
this instanceof ExactPathMatchSanitizer
@@ -77,11 +80,8 @@ private class DefaultUrlDecodeCall extends UrlDecodeCall {
7780
/** A repeated call to a method that decodes a URL. */
7881
abstract class RepeatedUrlDecodeCall extends MethodCall { }
7982

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 }
8585
}
8686

8787
/** A method call that checks a string for URL encoding. */
@@ -94,17 +94,19 @@ private class DefaultCheckUrlEncodingCall extends CheckUrlEncodingCall {
9494
}
9595
}
9696

97+
/** A guard that looks for a method call that checks for URL encoding. */
9798
private class CheckUrlEncodingGuard extends Guard instanceof CheckUrlEncodingCall {
9899
Expr getCheckedExpr() { result = this.(MethodCall).getQualifier() }
99100
}
100101

102+
/** Holds if `g` is guard for a URL that does not contain URL encoding. */
101103
private predicate noUrlEncodingGuard(Guard g, Expr e, boolean branch) {
102104
g instanceof CheckUrlEncodingGuard and
103105
e = g.(CheckUrlEncodingGuard).getCheckedExpr() and
104106
branch = false
105107
or
106108
branch = false and
107-
g.(Expr).getType() instanceof BooleanType and // TODO: remove debugging comment: // AssignExpr
109+
g.(Expr).getType() instanceof BooleanType and
108110
(
109111
exists(CheckUrlEncodingCall call, AssignExpr ae |
110112
ae.getSource() = call and
@@ -115,24 +117,25 @@ private predicate noUrlEncodingGuard(Guard g, Expr e, boolean branch) {
115117
exists(CheckUrlEncodingCall call, LocalVariableDeclExpr vde |
116118
vde.getInitOrPatternSource() = call and
117119
e = call.getQualifier() and
118-
g = vde.getAnAccess() //and
119-
//vde.getVariable() = g
120-
// TODO: remove debugging comments above
120+
g = vde.getAnAccess()
121121
)
122122
)
123123
}
124124

125+
/** A barrier for URLs that do not contain URL encoding. */
125126
private class NoUrlEncodingBarrier extends DataFlow::Node {
126127
NoUrlEncodingBarrier() { this = DataFlow::BarrierGuard<noUrlEncodingGuard/3>::getABarrierNode() }
127128
}
128129

130+
/** Holds if `g` is guard for a URL that is fully decoded. */
129131
private predicate fullyDecodesUrlGuard(Expr e) {
130132
exists(CheckUrlEncodingGuard g, RepeatedUrlDecodeCall decodeCall |
131133
e = g.getCheckedExpr() and
132134
g.controls(decodeCall.getBasicBlock(), true)
133135
)
134136
}
135137

138+
/** A barrier for URLs that are fully decoded. */
136139
private class FullyDecodesUrlBarrier extends DataFlow::Node {
137140
FullyDecodesUrlBarrier() {
138141
exists(Variable v, Expr e | this.asExpr() = v.getAnAccess() |

0 commit comments

Comments
 (0)