Skip to content

Commit

Permalink
Do not allow extra CRs in chunks (#11936)
Browse files Browse the repository at this point in the history
* Do not allow extra CRs in chunks

* Renumber test uuid

* Add test cases and fix an oversight

* Use prefix increment
  • Loading branch information
maskit authored Jan 3, 2025
1 parent 43b68ee commit f5f2256
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/proxy/http/HttpTunnel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ ChunkedHandler::read_size()
{
int64_t bytes_used;
bool done = false;
int cr = 0;

while (chunked_reader->read_avail() > 0 && !done) {
const char *tmp = chunked_reader->start();
Expand Down Expand Up @@ -186,6 +187,9 @@ ChunkedHandler::read_size()
done = true;
break;
} else {
if (ParseRules::is_cr(*tmp)) {
++cr;
}
state = CHUNK_READ_SIZE_CRLF; // now look for CRLF
}
}
Expand All @@ -195,7 +199,15 @@ ChunkedHandler::read_size()
cur_chunk_bytes_left = (cur_chunk_size = running_sum);
state = (running_sum == 0) ? CHUNK_READ_TRAILER_BLANK : CHUNK_READ_CHUNK;
done = true;
cr = 0;
break;
} else if (ParseRules::is_cr(*tmp)) {
if (cr != 0) {
state = CHUNK_READ_ERROR;
done = true;
break;
}
++cr;
}
} else if (state == CHUNK_READ_SIZE_START) {
if (ParseRules::is_cr(*tmp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def runChunkedTraffic(self):
# code from the verifier client.
tr.Processes.Default.ReturnCode = 1
tr.Processes.Default.Streams.stdout += Testers.ContainsExpression(
r"(Unexpected chunked content for key 4: too small|Failed HTTP/1 transaction with key: 4)",
r"(Unexpected chunked content for key 101: too small|Failed HTTP/1 transaction with key: 101)",
"Verify that ATS closed the forth transaction.")
tr.Processes.Default.Streams.stdout += Testers.ContainsExpression(
r"(Unexpected chunked content for key 5: too small|Failed HTTP/1 transaction with key: 5)",
r"(Unexpected chunked content for key 102: too small|Failed HTTP/1 transaction with key: 102)",
"Verify that ATS closed the fifth transaction.")
tr.Processes.Default.Streams.stdout += Testers.ContainsExpression(
r"(Unexpected chunked content for key 6: too small|Failed HTTP/1 transaction with key: 6)",
r"(Unexpected chunked content for key 103: too small|Failed HTTP/1 transaction with key: 103)",
"Verify that ATS closed the sixth transaction.")

# ATS should close the connection before any body gets through. "def"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ sessions:
server-response:
status: 200

- transactions:
- client-request:
method: "POST"
version: "1.1"
url: /malformed/chunk/header3
headers:
fields:
- [ Host, example.com ]
- [ Transfer-Encoding, chunked ]
- [ uuid, 4 ]
content:
transfer: plain
encoding: uri
# BWS cannot have CR
data: 3%0D%0D%0Aabc%0D%0A0%0D%0A%0D%0A

# The connection will be dropped and this response will not go out.
server-response:
status: 200

#
# Now repeat the above two malformed chunk header tests, but on the server
# side.
Expand All @@ -90,7 +110,7 @@ sessions:
headers:
fields:
- [ Host, example.com ]
- [ uuid, 4 ]
- [ uuid, 101 ]

# The connection will be dropped and this response will not go out.
server-response:
Expand All @@ -113,7 +133,7 @@ sessions:
headers:
fields:
- [ Host, example.com ]
- [ uuid, 5 ]
- [ uuid, 102 ]

# The connection will be dropped and this response will not go out.
server-response:
Expand All @@ -136,7 +156,7 @@ sessions:
headers:
fields:
- [ Host, example.com ]
- [ uuid, 6 ]
- [ uuid, 103 ]

# The connection will be dropped and this response will not go out.
server-response:
Expand All @@ -150,3 +170,26 @@ sessions:
encoding: uri
# Super large chunk header, larger than will fit in an int.
data: 111111113%0D%0Adef%0D%0A0%0D%0A%0D%0A

- transactions:
- client-request:
method: "GET"
version: "1.1"
url: /response/malformed/chunk/size2
headers:
fields:
- [ Host, example.com ]
- [ uuid, 104 ]

# The connection will be dropped and this response will not go out.
server-response:
status: 200
reason: OK
headers:
fields:
- [ Transfer-Encoding, chunked ]
content:
transfer: plain
encoding: uri
# BWS cannot have CR
data: 3%0D%0D%0Aabc%0D%0A0%0D%0A%0D%0A

0 comments on commit f5f2256

Please sign in to comment.