Skip to content

fix: reject whitespace between chunk-size digits (#1257) - #1290

Merged
pjfanning merged 1 commit into
apache:1.4.xfrom
pjfanning:wsp-14
Sep 10, 2026
Merged

fix: reject whitespace between chunk-size digits (#1257)#1290
pjfanning merged 1 commit into
apache:1.4.xfrom
pjfanning:wsp-14

Conversation

@pjfanning

Copy link
Copy Markdown
Member

cherry pick 7e39060 #1257

Motivation:
The chunk-size parser tolerates whitespace after the size digits (illegal per the spec but seen in the wild, see #1812), but the WSP arm recursed with the same accumulated size and then let parsing continue with the next character — including a further hex digit. So a chunk size such as 5 0 was read as 0x50 = 80 bytes, while a proxy that stops at the space reads 5. That discrepancy is a request- smuggling primitive when Pekko HTTP sits behind such a proxy. The comment referencing #1812 intended only trailing whitespace; the implementation skipped interior whitespace too. The WSP arm also had no cursor > offset guard, so a size field of only spaces parsed as 0.

Modification:
Thread a sawWhitespace flag through parseSize. Once whitespace has been seen, a hex digit no longer matches the accumulation arm and falls through to the illegal-character case, so only more whitespace or a terminator may follow. Guard the WSP arm with cursor > offset so leading whitespace (before any digit) is rejected as well.

Result:
Trailing whitespace after the chunk size is still tolerated, but whitespace between size digits, and leading whitespace, are rejected with "Illegal character '...' in chunk start" — Pekko HTTP and a fronting proxy can no longer disagree on the chunk size.

Tests:

  • sbt "http-core/testOnly org.apache.pekko.http.impl.engine.parsing.RequestParserCRLFSpec org.apache.pekko.http.impl.engine.parsing.RequestParserLFSpec" - pass (116 tests); two new tests reject 5 0 (interior whitespace) and 5 (leading whitespace), and the existing "incorrect but harmless whitespace after chunk size" test still passes. Verified the interior-whitespace test fails with the fix stashed (5 0 parses as 80 bytes).
  • sbt http-core/mimaReportBinaryIssues - pass (internal impl.engine.parsing change, no public API).

References:
Refs #1812 - narrows the whitespace tolerance to trailing whitespace only

Motivation:
The chunk-size parser tolerates whitespace after the size digits
(illegal per the spec but seen in the wild, see #1812), but the `WSP`
arm recursed with the same accumulated size and then let parsing
continue with the next character — including a further hex digit. So a
chunk size such as `5 0` was read as `0x50` = 80 bytes, while a proxy
that stops at the space reads 5. That discrepancy is a request-
smuggling primitive when Pekko HTTP sits behind such a proxy. The
comment referencing #1812 intended only trailing whitespace; the
implementation skipped interior whitespace too. The `WSP` arm also had
no `cursor > offset` guard, so a size field of only spaces parsed as 0.

Modification:
Thread a `sawWhitespace` flag through `parseSize`. Once whitespace has
been seen, a hex digit no longer matches the accumulation arm and falls
through to the illegal-character case, so only more whitespace or a
terminator may follow. Guard the `WSP` arm with `cursor > offset` so
leading whitespace (before any digit) is rejected as well.

Result:
Trailing whitespace after the chunk size is still tolerated, but
whitespace between size digits, and leading whitespace, are rejected
with "Illegal character '...' in chunk start" — Pekko HTTP and a
fronting proxy can no longer disagree on the chunk size.

Tests:
- sbt "http-core/testOnly org.apache.pekko.http.impl.engine.parsing.RequestParserCRLFSpec org.apache.pekko.http.impl.engine.parsing.RequestParserLFSpec" - pass (116 tests); two new tests reject `5 0` (interior whitespace) and ` 5` (leading whitespace), and the existing "incorrect but harmless whitespace after chunk size" test still passes. Verified the interior-whitespace test fails with the fix stashed (`5 0` parses as 80 bytes).
- sbt http-core/mimaReportBinaryIssues - pass (internal impl.engine.parsing change, no public API).

References:
Refs #1812 - narrows the whitespace tolerance to trailing whitespace only
@pjfanning pjfanning added this to the 1.4.2 milestone Sep 10, 2026
@pjfanning
pjfanning merged commit 5d840eb into apache:1.4.x Sep 10, 2026
10 checks passed
@pjfanning
pjfanning deleted the wsp-14 branch September 10, 2026 09:55
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