Skip to content

Commit c732cb7

Browse files
committed
Add HTTP Request Splitting to Netty Query
1 parent 6483a92 commit c732cb7

File tree

4 files changed

+94
-14
lines changed

4 files changed

+94
-14
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class NettyRequestSplitting {
2+
// BAD: Disables the internal response splitting verification
3+
private final DefaultHttpHeaders badHeaders = new DefaultHttpHeaders(false);
4+
5+
// GOOD: Verifies headers passed don't contain CRLF characters
6+
private final DefaultHttpHeaders goodHeaders = new DefaultHttpHeaders();
7+
8+
// BAD: Disables the internal response splitting verification
9+
private final DefaultHttpRequest badRequest = new DefaultHttpRequest(httpVersion, method, uri, false);
10+
11+
// GOOD: Verifies headers passed don't contain CRLF characters
12+
private final DefaultHttpRequest goodResponse = new DefaultHttpRequest(httpVersion, method, uri);
13+
}

java/ql/src/Security/CWE/CWE-113/NettyResponseSplitting.ql

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,78 @@
77
* @problem.severity error
88
* @security-severity 6.1
99
* @precision high
10-
* @id java/netty-http-response-splitting
10+
* @id java/netty-http-request-or-response-splitting
1111
* @tags security
1212
* external/cwe/cwe-113
1313
*/
1414

1515
import java
16+
import semmle.code.java.dataflow.FlowSources
1617

17-
abstract private class InsecureNettyObjectCreation extends ClassInstanceExpr { }
18+
abstract private class InsecureNettyObjectCreation extends ClassInstanceExpr {
19+
int vulnerableArgumentIndex;
1820

19-
private class InsecureDefaultHttpHeadersClassInstantiation extends InsecureNettyObjectCreation {
21+
InsecureNettyObjectCreation() {
22+
DataFlow::localExprFlow(any(CompileTimeConstantExpr ctce | ctce.getBooleanValue() = false), this.getArgument(vulnerableArgumentIndex))
23+
}
24+
25+
abstract string splittingType();
26+
}
27+
28+
abstract private class RequestOrResponseSplittingInsecureNettyObjectCreation extends InsecureNettyObjectCreation {
29+
override string splittingType() { result = "Request-splitting or response-splitting" }
30+
}
31+
32+
/**
33+
* Request splitting can allowing an attacker to inject/smuggle an additional HTTP request into the socket connection.
34+
*/
35+
abstract private class RequestSplittingInsecureNettyObjectCreation extends InsecureNettyObjectCreation {
36+
override string splittingType() { result = "Request-splitting" }
37+
}
38+
39+
/**
40+
* Response splitting can lead to HTTP vulnerabilities like XSS and cache poisoning.
41+
*/
42+
abstract private class ResponseSplittingInsecureNettyObjectCreation extends InsecureNettyObjectCreation {
43+
override string splittingType() { result = "Response-splitting" }
44+
}
45+
46+
private class InsecureDefaultHttpHeadersClassInstantiation extends RequestOrResponseSplittingInsecureNettyObjectCreation {
2047
InsecureDefaultHttpHeadersClassInstantiation() {
21-
getConstructedType().hasQualifiedName("io.netty.handler.codec.http", "DefaultHttpHeaders") and
22-
getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = false
48+
getConstructedType()
49+
.hasQualifiedName("io.netty.handler.codec.http",
50+
["DefaultHttpHeaders", "CombinedHttpHeaders"]) and
51+
vulnerableArgumentIndex = 0
2352
}
2453
}
2554

26-
private class InsecureDefaultHttpResponseClassInstantiation extends InsecureNettyObjectCreation {
55+
private class InsecureDefaultHttpResponseClassInstantiation extends ResponseSplittingInsecureNettyObjectCreation {
2756
InsecureDefaultHttpResponseClassInstantiation() {
2857
getConstructedType().hasQualifiedName("io.netty.handler.codec.http", "DefaultHttpResponse") and
29-
getArgument(2).(CompileTimeConstantExpr).getBooleanValue() = false
58+
vulnerableArgumentIndex = 2
59+
}
60+
}
61+
62+
private class InsecureDefaultHttpRequestClassInstantiation extends RequestSplittingInsecureNettyObjectCreation {
63+
InsecureDefaultHttpRequestClassInstantiation() {
64+
getConstructedType().hasQualifiedName("io.netty.handler.codec.http", "DefaultHttpRequest") and
65+
vulnerableArgumentIndex = 3
3066
}
3167
}
3268

33-
private class InsecureDefaultFullHttpResponseClassInstantiation extends InsecureNettyObjectCreation {
69+
private class InsecureDefaultFullHttpResponseClassInstantiation extends ResponseSplittingInsecureNettyObjectCreation {
3470
InsecureDefaultFullHttpResponseClassInstantiation() {
3571
getConstructedType().hasQualifiedName("io.netty.handler.codec.http", "DefaultFullHttpResponse") and
36-
getArgument(3).(CompileTimeConstantExpr).getBooleanValue() = false
72+
vulnerableArgumentIndex = [2, 3]
73+
}
74+
}
75+
76+
private class InsecureDefaultFullHttpRequestClassInstantiation extends RequestSplittingInsecureNettyObjectCreation {
77+
InsecureDefaultFullHttpRequestClassInstantiation() {
78+
getConstructedType().hasQualifiedName("io.netty.handler.codec.http", "DefaultFullHttpRequest") and
79+
vulnerableArgumentIndex = [3, 4]
3780
}
3881
}
3982

4083
from InsecureNettyObjectCreation new
41-
select new, "Response-splitting vulnerability due to header value verification being disabled."
84+
select new, new.splittingType() + " vulnerability due to header value verification being disabled."

java/ql/src/Security/CWE/CWE-113/ResponseSplitting.qhelp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55

66
<overview>
77
<p>Directly writing user input (for example, an HTTP request parameter) to an HTTP header
8-
can lead to an HTTP response-splitting vulnerability.
9-
If the user input includes blank lines in it, and if the servlet container does not itself
10-
escape the blank lines, then a remote user can cause the response to turn into two separate
11-
responses, one of which is controlled by the remote user.</p>
8+
can lead to an HTTP request-splitting or response-splitting vulnerability.</p>
9+
10+
<p>HTTP Response-splitting can lead to vulnerabilities such as XSS, and cache poisoning.</p>
11+
<p>HTTP Request-splitting can allow an attacker to inject/smuggle an additional HTTP request into a client's outgoing socket connection.
12+
This can allow an attacker to perform an SSRF-like attack.</p>
13+
14+
<p>In the context of a servlet container, if the user input includes blank lines,
15+
and if the servlet container does not itself escape the blank lines,
16+
then a remote user can cause the response to turn into two separate responses,
17+
one of which is controlled by the remote user. This is also HTTP Response-splitting.</p>
1218
</overview>
1319

1420
<recommendation>
1521
<p>Guard against HTTP header splitting in the same way as guarding against cross-site scripting.
1622
Before passing any data into HTTP headers, either check the data for special characters, or
1723
escape any special characters that are present.</p>
24+
25+
<p>In the case of code calling Netty API's directly, ensure that the <code>validateHeaders</code> parameter is set to <code>true</code>.</p>
1826
</recommendation>
1927

2028
<example>
@@ -33,6 +41,13 @@ The second way will verify the parameters before using them to build the HTTP re
3341
<sample src="NettyResponseSplitting.java" />
3442
</example>
3543

44+
<example>
45+
<p>The following example shows the use of the library 'netty' with HTTP request-splitting verification configurations.
46+
The second way will verify the parameters before using them to build the HTTP request.</p>
47+
48+
<sample src="NettyRequestSplitting.java" />
49+
</example>
50+
3651
<references>
3752
<li>
3853
InfosecWriters: <a href="http://www.infosecwriters.com/Papers/DCrab_HTTP_Response.pdf">HTTP response splitting</a>.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
category: breaking
3+
---
4+
* Add more classes to Netty request/response splitting. Change identification to `java/netty-http-request-or-response-splitting`.
5+
Identify request splitting differently from response splitting in query results.
6+
Support addional classes:
7+
* `io.netty.handler.codec.http.CombinedHttpHeaders`
8+
* `io.netty.handler.codec.http.DefaultHttpRequest`
9+
* `io.netty.handler.codec.http.DefaultFullHttpRequest`

0 commit comments

Comments
 (0)