fix: drop rendered headers containing NUL as well as CR and LF - #1260
Open
pjfanning wants to merge 1 commit into
Open
fix: drop rendered headers containing NUL as well as CR and LF#1260pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
Motivation: The guard in `Rendering.~~(HttpHeader)` renders a header and then scans the rendered bytes, discarding the header if it finds one of the characters that must never reach the wire. It only looked for CR and LF, so a `RawHeader` value carrying a NUL was rendered as-is. NUL is not a legal field-value character, and a downstream consumer that treats the value as a C string truncates it there, so two parties can disagree about where the value ends. The HTTP/2 renderer rejects CR, LF and NUL alike, so HTTP/1.1 was the weaker of the two. Modification: Add `Rendering.isIllegalHeaderChar`, which covers CR, LF and NUL, and use it from all four `check` implementations (`StringRendering`, `ByteArrayRendering`, `ByteStringRendering` and `CustomCharsetByteStringRendering`) instead of repeating the character comparison a fourth time. It takes an `Int` so the `Char` and `Byte` based renderings can pass their element straight in. Result: A header whose name or value contains NUL is discarded like one containing CR or LF, on every rendering implementation, and the rule now lives in one place. Tests: - sbt "http-core/testOnly org.apache.pekko.http.impl.util.RenderingSpec org.apache.pekko.http.impl.engine.rendering.ResponseRendererSpec org.apache.pekko.http.impl.engine.rendering.RequestRendererSpec" - pass (80 tests); a new case in the shared rendering table asserts a header with NUL in the value is discarded. Verified it fails with the fix stashed, once for each of the four renderings. - sbt http-core/mimaReportBinaryIssues - pass (internal impl.util change, no public API). References: None - extends the outgoing header guard to NUL
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.
Motivation
The guard in
Rendering.~~(HttpHeader)renders a header and then scans the rendered bytes, discarding it if it finds a character that must never reach the wire. It only looked for CR and LF:so a
RawHeadervalue carrying a NUL was rendered as-is. NUL is not a legal field-value character, and a downstream consumer that treats the value as a C string truncates it there — so two parties can disagree about where the value ends. The HTTP/2 renderer rejects CR, LF and NUL alike (see #1258), which left HTTP/1.1 as the weaker of the two.Modification
Add
Rendering.isIllegalHeaderChar, covering CR, LF and NUL, and call it from all fourcheckimplementations —StringRendering,ByteArrayRendering,ByteStringRenderingandCustomCharsetByteStringRendering— rather than repeating the character comparison a fourth time. It takes anIntso theChar- andByte-based renderings can pass their element straight in.Result
A header whose name or value contains NUL is discarded like one containing CR or LF, on every rendering implementation, and the rule now lives in one place.
Tests
sbt "http-core/testOnly org.apache.pekko.http.impl.util.RenderingSpec org.apache.pekko.http.impl.engine.rendering.ResponseRendererSpec org.apache.pekko.http.impl.engine.rendering.RequestRendererSpec"— pass (80 tests). A new case in the shared rendering table asserts a header with NUL in the value is discarded. Verified it fails with the fix stashed — once for each of the four renderings.sbt http-core/mimaReportBinaryIssues— pass (internalimpl.utilchange, no public API).scalafmton the changed files — clean.References
None - extends the outgoing header guard to NUL
🤖 Generated with Claude Code