sahvx655-wq commented on code in PR #3758:
URL: https://github.com/apache/brpc/pull/3758#discussion_r4639233003
##########
test/brpc_http_message_unittest.cpp:
##########
@@ -630,6 +630,54 @@ TEST(HttpMessageTest, chunked_trailer_is_not_a_header) {
ASSERT_EQ("10.0.0.1", *xff);
}
+TEST(HttpMessageTest, ctl_in_chunk_extension) {
+ // A peer that ends the chunk-size line at the bare LF reads one request
+ // with chunks "xx" and 0x31 bytes. Skipping the LF as part of the
+ // extension read "31" as the chunk data instead, ended the request at
+ // "0\r\n\r\n" and parsed GET /smuggled as the next request.
+ const std::string smuggled =
+ "POST /a HTTP/1.1\r\n"
+ "Host: a.com\r\n"
+ "Transfer-Encoding: chunked\r\n\r\n"
+ "2;\nxx\r\n"
+ "31\r\n"
+ "0\r\n\r\n"
+ "GET /smuggled HTTP/1.1\r\nHost: a.com\r\nX: \r\n\r\n"
+ "0\r\n\r\n";
Review Comment:
Right, I miscounted. The 49 bytes run through the blank line that ends the
inner request's headers, so they swallow the CRLF that has to follow the chunk
data, and an LF-terminating reader then finds `0\r` where it expects CRLF. A
small decoder that ends chunk lines at LF rejects that payload outright. The
scenario does hold with size 0x3f and `Content-Length: 7` on the inner request:
the LF reader sees one request (chunks `xx` and 63 bytes), while master
completes `/a` with body `3f` and then parses `GET /smuggled` with
`\r\n0\r\n\r\n` as its body. I've corrected the example in the description to
that one.
The test now follows your suggestion. A valid chunked request with `5;a=b`
and `0;c=d` is parsed first and has to be fully consumed with body `hello`,
then only the extension bytes are swapped (`a\nb`, `a\x7fb`, `a\x01b`, `c\nd`)
and each has to fail with `HPE_INVALID_CHUNK_SIZE`. The old rejected list is
folded into that since it covered the same cases. I ran the test body against
the real parser with thin IOBuf/HttpMessage stand-ins, not a full build: the
control parses on master and with the fix, and the four mutations are accepted
on master and rejected with the fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]