fix: reject a message whose Transfer-Encoding value cannot be parsed - #1291
Merged
Conversation
…pache#1267) Motivation: When a modelled header value fails to parse, `ModeledHeaderValueParser` calls `onIllegalHeader` - which by default only logs - and degrades the header to a `RawHeader`. For `Transfer-Encoding` that is unsafe: the degraded header never reaches the `case h: Transfer-Encoding` arm in `parseHeaderLines`, so `isChunked` stays false and, with a Content-Length also present, the message is framed by Content-Length. An upstream that does parse the value - stripping quotes, tolerating trailing junk - frames the same message as chunked. The two disagree about where the message ends, which is a request smuggling primitive. Pekko HTTP already rejects the clear cases: `chunked` together with a Content-Length, an unsupported coding, and multiple entries. Only the unparseable value was silently tolerated. Modification: Fail the message when a `Transfer-Encoding` header arrives as a `RawHeader`. That can only happen when the modelled parse failed: `transfer-encoding` is in `alwaysParsedHeaders`, so it is modelled even when `modeled-header-parsing` is off, and a well-formed value always reaches the modelled arm. Result: A message whose Transfer-Encoding cannot be understood is rejected rather than framed by a different rule than the sender used. Tests: - sbt "http-core/testOnly org.apache.pekko.http.impl.engine.parsing.*" - pass (246 tests); a new test sends `Transfer-Encoding: "chunked"` alongside a Content-Length and expects a 400. Verified it fails without the change, where the message is accepted and framed by Content-Length. - sbt http-core/mimaReportBinaryIssues - pass References: None - rejects a message whose Transfer-Encoding value cannot be parsed
nvollmar
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cherry pick 44b01c3 #1267
Motivation:
When a modelled header value fails to parse,
ModeledHeaderValueParsercallsonIllegalHeader- which by default only logs - and degrades the header to aRawHeader. ForTransfer-Encodingthat is unsafe: the degraded header never reaches thecase h: Transfer-Encodingarm inparseHeaderLines, soisChunkedstays false and, with a Content-Length also present, the message is framed by Content-Length. An upstream that does parse the value - stripping quotes, tolerating trailing junk - frames the same message as chunked. The two disagree about where the message ends, which is a request smuggling primitive.Pekko HTTP already rejects the clear cases:
chunkedtogether with a Content-Length, an unsupported coding, and multiple entries. Only the unparseable value was silently tolerated.Modification:
Fail the message when a
Transfer-Encodingheader arrives as aRawHeader. That can only happen when the modelled parse failed:transfer-encodingis inalwaysParsedHeaders, so it is modelled even whenmodeled-header-parsingis off, and a well-formed value always reaches the modelled arm.Result:
A message whose Transfer-Encoding cannot be understood is rejected rather than framed by a different rule than the sender used.
Tests:
Transfer-Encoding: "chunked"alongside a Content-Length and expects a 400. Verified it fails without the change, where the message is accepted and framed by Content-Length.References:
None - rejects a message whose Transfer-Encoding value cannot be parsed