"09f55884dec3525b0a7031c056d63996b552eade": "Auto-port 4.1: Validate chunked-must-be-last regardless of HTTP version (#17228)\n\nAuto-port of #17055 to 4.1\nCherry-picked commit: fcf427d91c8321b3aa3f83af4a7029b98ce1753d\n\n---\n### Motivation\nRFC 9112 \u00a76.1 requires that when a message uses Transfer-Encoding,\n\"chunked\" must be the last encoding listed \u2014 a value like `chunked,\nidentity` is malformed. This rule was added to `HttpObjectDecoder`\nalongside the fix for CVE-2026-42581, nested inside a pre-existing\n`protocolVersion() == HttpVersion.HTTP_1_1` condition \u2014 the same\ncondition that gates a different, older check (the\nContent-Length/Transfer-Encoding conflict handling).\n\nUnder the default configuration this is harmless: an earlier guard\nalready rejects any Transfer-Encoding header on a non-1.1 message\noutright, so the ordering check's version scoping is not expected to be\nexercised under normal use. However,\n`HttpDecoderConfig#setUseRfc9112TransferEncoding(false)` is a documented\nopt-out for restoring RFC 7230 behavior, and under that configuration a\nnon-1.1 message can legitimately carry Transfer-Encoding without being\nrejected for it. In that case, the inherited version gate meant the\nchunked-must-be-last check was silently skipped for HTTP/1.0 (and other\nnon-1.1 versions) \u2014 a message with `Transfer-Encoding: chunked,\nidentity` would decode successfully instead of being rejected.\n\n### Modification\n\n- Extracted the chunked-must-be-last check from inside the\n`protocolVersion() == HTTP_1_1` block in `HttpObjectDecoder#readHeaders`\nand gave it its own, version-independent condition, since the RFC 9112\nordering rule has no dependency on protocol version.\n\n- Added two regression tests to `HttpRequestDecoderTest`: one\nreproducing the original scenario (HTTP/1.0,\n`useRfc9112TransferEncoding(false)`, `Transfer-Encoding: chunked,\nidentity)`, and a companion using a non-no-op trailing encoding\n(`chunked, gzip`) confirming the fix isn't tied to the specific encoding\nthat follows `chunked`.\n\n- Corrected a pre-existing inaccuracy in\n`handleTransferEncodingChunkedWithContentLength`'s javadoc, which stated\nthat earlier HTTP versions \"will reject requests that include\n[Transfer-Encoding]\" without qualification \u2014 true only under the default\nconfiguration, and already inaccurate before this change since\n`useRfc9112TransferEncoding(false)` predates it.\n\n### Result\n\n- The chunked-must-be-last validation now applies to any message\ncarrying a Transfer-Encoding header, independent of protocol version or\nthe `useRfc9112TransferEncoding` setting.\n\nSigned-off-by: husseinvr97 <husseinmustafabas05@gmail.com>\nCo-authored-by: Hussein Mustafa <husseinmustafabas05@gmail.com>\nCo-authored-by: Chris Vest <christianvest_hansen@apple.com>",
0 commit comments