Skip to content

Reject control characters at the boundary of the HTTP version token (#16971) - #16986

Merged
normanmaurer merged 2 commits into
4.1from
control41
Jun 26, 2026
Merged

normanmaurer merged 2 commits into
4.1from
control41

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

HttpRequestDecoder accepts a request whose HTTP-version token carries
a boundary control byte (NUL, CR, LF, VT, FF, …):

printf 'GET / \x00HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc <host> <port>

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 Reject control characters at the boundary of HTTP method names #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]

…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>
```

`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]>
@chrisvest chrisvest added this to the 4.1.136.Final milestone Jun 24, 2026
@normanmaurer
normanmaurer merged commit df54c37 into 4.1 Jun 26, 2026
16 of 19 checks passed
@normanmaurer
normanmaurer deleted the control41 branch June 26, 2026 13:31
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…etty#16971) (netty#16986)

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>
```

`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 netty#16723 (issue netty#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 netty#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 netty#16970

---------

Co-authored-by: Bryce Anderson <[email protected]>

---------

Co-authored-by: HwangRock <[email protected]>
Co-authored-by: Bryce Anderson <[email protected]>
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.

3 participants