Skip to content

Answer 400 to a bare LF in a chunk-size line - #1965

Open
Shrusti-pk wants to merge 1 commit into
uNetworking:masterfrom
Shrusti-pk:chunk-line-bare-lf
Open

Shrusti-pk wants to merge 1 commit into
uNetworking:masterfrom
Shrusti-pk:chunk-line-bare-lf

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

A chunk-size line is accepted when it ends in a bare LF, but RFC 9112 7.1 ends every chunk line in CRLF. consumeHexNumber has three spots:

  • right after the size the LF ends the line: 5\nhello\r\n
  • after an unquoted extension the LF ends the line too: 5;a=b\nhello\r\n
  • inside a quoted extension the LF is kept as extension text and the line runs on to the CRLF: 5;a="x\ny"\r\nhello\r\n

A parser that ends the line only on CRLF, or on any LF, then disagrees with uWS on where the chunk data starts (RFC 9112 11.2). With 25;a=b\n, 37 x, then \r\n0\r\n\r\nGET /admin HTTP/1.1\r\nHost: a\r\n\r\n\r\n0\r\n\r\n, a CRLF-only parser sees one POST with the GET inside the chunk data, and uWS dispatches the GET as a second request.

Now only the LF after a CR ends the line, and the two LF branches this leaves dead are removed. The chunk data CRLF and the trailer section (#1950) already answer 400 to a bare LF.

The new test in tests/HttpParser.cpp sends the three forms, a bare LF after the last chunk and two valid extensions, each followed by a pipelined GET. It fails without the fix. The rest of tests/, h1spec, the smoke test and the Http fuzzer pass.

RFC 9112 7.1 ends every chunk line in CRLF. consumeHexNumber took a
bare LF as the line end after the size and after an unquoted
extension, and kept it as extension text inside quotes, so a parser
that ends the line only on CRLF, or on any LF, can disagree with uWS
on where the chunk data starts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant