sahvx655-wq opened a new pull request, #3758:
URL: https://github.com/apache/brpc/pull/3758

   ### What problem does this PR solve?
   
   Issue Number: resolve 
   
   Problem Summary:
   
   `http_parser_execute` (src/brpc/details/http_parser.cpp) skips everything 
after `;` or SP on a chunk-size line until it sees CR (`s_chunk_parameters`), 
so a bare LF inside a chunk extension is swallowed as extension bytes. Every 
other line-scanning state in the parser treats LF as a line end, and front-ends 
that do the same on the chunk-size line read the bytes after the LF as chunk 
data. The two sides then disagree on chunk boundaries and on where the request 
ends, which is the chunk-extension variant of HTTP request smuggling ("funky 
chunks").
   
   Concrete trigger, request body under `Transfer-Encoding: chunked`:
   
   ```
   2;\nxx\r\n
   31\r\n
   0\r\n\r\nGET /smuggled HTTP/1.1\r\nHost: a.com\r\nX: \r\n\r\n
   0\r\n\r\n
   ```
   
   A proxy that ends the line at LF forwards one request with chunks `xx` and 
0x31 bytes. brpc reads `31` as the 2-byte chunk, ends the request at 
`0\r\n\r\n` and parses `GET /smuggled` as the next request on the connection, 
bypassing whatever routing or access rules the proxy applied to it. RFC 9112 
7.1.1 allows no CTL other than HTAB anywhere in chunk-ext (token, 
quoted-string, BWS).
   
   ### What is changed and the side effects?
   
   Changed:
   
   - `s_chunk_parameters` rejects LF and other CTLs (everything 
`IS_HEADER_CHAR` refuses) with `HPE_INVALID_CHUNK_SIZE`. CR still ends the line 
as before. The check sits in the parser state itself because that is the only 
place that knows the bytes belong to a chunk extension.
   - `HttpMessageTest.ctl_in_chunk_extension` covers the smuggling payload 
above, a bare LF and DEL in a normal chunk and a bare LF on the last-chunk 
line, plus extensions that must keep parsing (`name=val`, quoted-string 
containing SP and `;`, HTAB as BWS).
   
   Verified by compiling http_parser.cpp on its own with a harness that pauses 
on message_complete the same way `HttpMessage` does: on master the smuggling 
payload completes the first request with body `31` and the other three rejected 
cases are accepted; with the fix all four fail with `HPE_INVALID_CHUNK_SIZE` 
and the accepted cases still parse. The new gtest was not run in a full brpc 
build.
   
   Side effects:
   - Performance effects: one extra byte-class check per chunk-extension byte; 
none for chunks without extensions.
   
   - Breaking backward compatibility: peers that put raw control characters 
other than HTAB in chunk extensions are now rejected. Those messages are 
malformed under RFC 9112.
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
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]

Reply via email to