Skip to content

Commit e5d624d

Browse files
Add open redirect sinks
1 parent e3fe635 commit e5d624d

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

java/ql/src/semmle/code/java/frameworks/ApacheHttp.qll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ class ApacheHttpRequestHandlerParameter extends Parameter {
5656
}
5757
}
5858

59+
/**
60+
* A call that sets a header of an `HttpResponse`.
61+
*/
62+
class ApacheHttpSetHeader extends Call {
63+
ApacheHttpSetHeader() {
64+
exists(Method m |
65+
this.getCallee().(Method).overrides*(m) and
66+
m.getDeclaringType()
67+
.hasQualifiedName(["org.apache.http", "org.apache.hc.core5.http"], "HttpMessage") and
68+
m.hasName(["addHeader", "setHeader"]) and
69+
m.getNumberOfParameters() = 2
70+
)
71+
or
72+
exists(Constructor c |
73+
this.getCallee() = c and
74+
c.getDeclaringType()
75+
.hasQualifiedName(["org.apache.http.message", "org.apache.hc.core5.http.message"],
76+
"BasicHeader")
77+
)
78+
}
79+
80+
/** Gets the expression used as the name of this header. */
81+
Expr getName() { result = this.getArgument(0) }
82+
83+
/** Gets the expression used as the value of this header. */
84+
Expr getValue() { result = this.getArgument(1) }
85+
}
86+
5987
/**
6088
* A call that sets the entity of an instance of `org.apache.http.HttpResponse` / `org.apache.hc.core5.http.ClassicHttpResponse`.
6189
*/
@@ -146,6 +174,9 @@ private class ApacheHttpGetter extends TaintPreservingCallable {
146174
or
147175
ty = "HttpEntity" and
148176
mtd = ["getContent", "getTrailers"]
177+
or
178+
ty = "EntityDetails" and
179+
mtd = ["getContentType", "getTrailerNames"]
149180
)
150181
or
151182
pkg = "org.apache.hc.core5.message" and

java/ql/src/semmle/code/java/security/UrlRedirect.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java
44
import semmle.code.java.dataflow.DataFlow
55
import semmle.code.java.frameworks.Servlets
6+
import semmle.code.java.frameworks.ApacheHttp
67

78
/** A URL redirection sink */
89
abstract class UrlRedirectSink extends DataFlow::Node { }
@@ -24,3 +25,13 @@ private class ServletUrlRedirectSink extends UrlRedirectSink {
2425
)
2526
}
2627
}
28+
29+
/** A URL redirection sink from Apache Http components. */
30+
private class ApacheUrlRedirectSink extends UrlRedirectSink {
31+
ApacheUrlRedirectSink() {
32+
exists(ApacheHttpSetHeader c |
33+
c.getName().(CompileTimeConstantExpr).getStringValue() = "Location" and
34+
this.asExpr() = c.getValue()
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)