Skip to content

Answer 400 to a Content-Length that reaches the chunked state bits - #1969

Merged
uNetworkingAB merged 1 commit into
uNetworking:masterfrom
Shrusti-pk:content-length-state-bits
Nov 19, 2026
Merged

uNetworkingAB merged 1 commit into
uNetworking:masterfrom
Shrusti-pk:content-length-state-bits

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

A Content-Length of 2^56 or more is accepted, and the body after the first read is then parsed as chunked encoding. HttpParser keeps the Content-Length in remainingStreamingBytes, whose top 8 bits are the chunked state from ChunkedEncoding.h (STATE_IS_CHUNKED, STATE_EXTENSION_* and so on). toUnsignedInteger allows 18 digits, so Content-Length: 72057594037927936 sets STATE_EXTENSION_IN_NAME, and on the next read isParsingChunkedEncoding() is true.

Repro: send POST / HTTP/1.1\r\nHost: a\r\nContent-Length: 72057594037927936\r\n\r\n, then in a second read 0\r\n\r\nGET /admin HTTP/1.1\r\nHost: a\r\n\r\n. For a proxy in front this is one POST with a long body, but uWS ends the POST at the 0 chunk and dispatches GET /admin as a second request (request smuggling, RFC 9112 11.2).

The fix answers 400 to any Content-Length above STATE_SIZE_MASK (2^56 - 1, about 72 PB), which also covers the UINT64_MAX error value. The check is in the Content-Length branch because that is the only place a fixed length goes into remainingStreamingBytes.

The new test in tests/HttpParser.cpp sends the body in a second read for 2^56 - 1, 2^56 and 999999999999999999. It fails without the fix.

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.

2 participants