Repository navigation
Auto-port 5.0: Reject control characters at the boundary of the HTTP version token - #16981
Merged
Merged
Conversation
…16971) Motivation: `HttpRequestDecoder` accepts a request whose HTTP-version token carries a boundary control byte (`NUL`, `CR`, `LF`, `VT`, `FF`, …): ```bash printf 'GET / \x00HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc <host> <port> # decoded as a clean HTTP/1.1 request; no decoder failure ``` `HttpVersion.valueOf(String, boolean)` ran `text.trim()` before matching the version, and `String.trim()` removes every character with code point `<= 0x20`. The boundary control byte was therefore silently stripped and the surviving `"HTTP/1.1"` matched the cached constant, so the malformed request decoded as a clean `HTTP/1.1` one. The method token on the same request line already rejects such a byte since #16723 (issue #15047), so the two tokens were inconsistent — this is the same boundary-control-character / request-smuggling class, left open for the version token. Modification: - `HttpVersion`: drop the `trim()` in `valueOf` and in the `HttpVersion(String, boolean, boolean)` constructor. The existing strict format check (`length == 8 && startsWith("HTTP/") && charAt(6) == '.'`) now rejects a token padded with a control byte, and the non-strict path rejects control/whitespace in the protocol name via `hasControlOrWhitespace`. Without the `trim()`, `SP`/`HT` padding is rejected too, mirroring the method-token behaviour from #16723. - `RtspVersions.valueOf`: drop the `trim()` the same way. `HttpRequestDecoder` already turns `createMessage` exceptions into a decoder failure, so the wire effect is `decoderResult().isSuccess() == false` instead of a phantom `HTTP/1.1`. Result: Before this change `"GET / \x00HTTP/1.1\r\n…"` decoded successfully (`decoderResult().isSuccess() == true`, `protocolVersion() == HTTP_1_1`); after it the decoder reports a failure, matching the method-token behaviour. A clean `HTTP/1.1` request still decodes as before. ``` Test set: io.netty.handler.codec.http.HttpVersionParsingTest Tests run: 53, Failures: 0, Errors: 0, Skipped: 0 Test set: io.netty.handler.codec.http.HttpRequestDecoderTest Tests run: 85, Failures: 0, Errors: 0, Skipped: 0 Test set: io.netty.handler.codec.rtsp.RtspDecoderTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 Test set: io.netty.handler.codec.rtsp.RtspEncoderTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 ``` Fixes #16970 --------- Co-authored-by: Bryce Anderson <[email protected]> (cherry picked from commit 69b7851)
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.
Auto-port of #16971 to 5.0
Cherry-picked commit: 69b7851
Motivation:
HttpRequestDecoderaccepts a request whose HTTP-version token carries a boundary control byte (NUL,CR,LF,VT,FF, …):HttpVersion.valueOf(String, boolean)rantext.trim()before matching the version, andString.trim()removes every character with code point<= 0x20. The boundary control byte was therefore silently stripped and the surviving"HTTP/1.1"matched the cached constant, so the malformed request decoded as a cleanHTTP/1.1one.The method token on the same request line already rejects such a byte since #16723 (issue #15047), so the two tokens were inconsistent — this is the same boundary-control-character / request-smuggling class, left open for the version token.
Modification:
HttpVersion: drop thetrim()invalueOfand in theHttpVersion(String, boolean, boolean)constructor. The existing strict format check (length == 8 && startsWith("HTTP/") && charAt(6) == '.') now rejects a token padded with a control byte, and the non-strict path rejects control/whitespace in the protocol name viahasControlOrWhitespace. Without thetrim(),SP/HTpadding is rejected too, mirroring the method-token behaviour from Reject control characters at the boundary of HTTP method names #16723.RtspVersions.valueOf: drop thetrim()the same way.HttpRequestDecoderalready turnscreateMessageexceptions into a decoder failure, so the wire effect isdecoderResult().isSuccess() == falseinstead of a phantomHTTP/1.1.Result:
Before this change
"GET / \x00HTTP/1.1\r\n…"decoded successfully (decoderResult().isSuccess() == true,protocolVersion() == HTTP_1_1); after it the decoder reports a failure, matching the method-token behaviour. A cleanHTTP/1.1request still decodes as before.Fixes #16970