Skip to content

Reject all control characters and DEL in HTTP response reason phrases - #18331

Merged
normanmaurer merged 2 commits into
netty:4.2from
qchole:fix/http-response-reason-phrase-control-chars
Nov 13, 2026
Merged

normanmaurer merged 2 commits into
netty:4.2from
qchole:fix/http-response-reason-phrase-control-chars

Conversation

@qchole

@qchole qchole commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Motivation:

HttpResponseStatus only rejected CR and LF in the reason phrase. Other control characters (NUL, VT, FF, ...) and DEL were still accepted when parsing a response status line and written verbatim to the wire by HttpResponseEncoder. Lenient downstream parsers may treat these as line separators (response splitting / desync) and C-string based parsers may truncate at NUL. This closes the sibling gap of the request line hardening: RFC 9110 defines the reason-phrase as
*( HTAB / SP / VCHAR / obs-text ).

Modification:

Reject every control character except HTAB, and DEL, in the HttpResponseStatus reason phrase. HTAB and SP remain legal.

Result:

A response with control characters in its reason phrase is now rejected by the decoder instead of being accepted and re-encoded verbatim.

qchole and others added 2 commits November 10, 2026 11:29
Motivation:

HttpResponseStatus only rejected CR and LF in the reason phrase. Other
control characters (NUL, VT, FF, ...) and DEL were still accepted when
parsing a response status line and written verbatim to the wire by
HttpResponseEncoder. Lenient downstream parsers may treat these as line
separators (response splitting / desync) and C-string based parsers may
truncate at NUL. This closes the sibling gap of the request line
hardening: RFC 9110 defines the reason-phrase as
*( HTAB / SP / VCHAR / obs-text ).

Modification:

- Reject every control character except HTAB, and DEL, in the
  HttpResponseStatus reason phrase. HTAB and SP remain legal.
- Add regression tests for the constructor, parseLine and the response
  decoder, including acceptance of HTAB and obs-text.

Result:

A response with control characters in its reason phrase is now rejected
by the decoder (BAD_MESSAGE) instead of being accepted and re-encoded
verbatim.

Potentially breaking: HttpResponseStatus now throws
IllegalArgumentException for reason phrases containing control
characters (except HTAB) or DEL.
@testlens-app

testlens-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 167a209
▶️ Tests: 59786 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

@normanmaurer

Copy link
Copy Markdown
Member

@franz1981 PTAL

@normanmaurer

Copy link
Copy Markdown
Member

@qchole please sign our ICLA and let me know once done: https://netty.io/s/icla

@qchole

qchole commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@qchole please sign our ICLA and let me know once done: https://netty.io/s/icla

@normanmaurer Done — I've signed the ICLA.

@normanmaurer normanmaurer added this to the 4.2.21.Final milestone Nov 13, 2026
@normanmaurer
normanmaurer merged commit aa30b7a into netty:4.2 Nov 13, 2026
27 checks passed
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Nov 13, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #18381

@normanmaurer

Copy link
Copy Markdown
Member

Ported to 5.0: #18382

@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 13, 2026
@qchole
qchole deleted the fix/http-response-reason-phrase-control-chars branch November 13, 2026 14:34
normanmaurer added a commit that referenced this pull request Nov 13, 2026
Motivation:

The auto-port of #18331 added tests using lambda expressions, but the 4.1
branch compiles tests with -source 1.6, so verify-pr failed with
'lambda expressions are not supported in -source 1.6'.

Modification:

Replace the lambdas with anonymous Executable classes and drop the
assertThatThrownBy usage in favour of assertThrows plus assertThat.

Result:

The tests compile on the 4.1 Java 6 baseline.
chrisvest pushed a commit that referenced this pull request Nov 13, 2026
… reason phrases (#18381)

Auto-port of #18331 to 4.1
Cherry-picked commit: aa30b7a

---
Motivation:

HttpResponseStatus only rejected CR and LF in the reason phrase. Other
control characters (NUL, VT, FF, ...) and DEL were still accepted when
parsing a response status line and written verbatim to the wire by
HttpResponseEncoder. Lenient downstream parsers may treat these as line
separators (response splitting / desync) and C-string based parsers may
truncate at NUL. This closes the sibling gap of the request line
hardening: RFC 9110 defines the reason-phrase as
*( HTAB / SP / VCHAR / obs-text ).

Modification:

Reject every control character except HTAB, and DEL, in the
HttpResponseStatus reason phrase. HTAB and SP remain legal.

Result:

A response with control characters in its reason phrase is now rejected
by the decoder instead of being accepted and re-encoded verbatim.

---------

Co-authored-by: 秦利斌 <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
chrisvest pushed a commit that referenced this pull request Nov 13, 2026
…on phrases (#18331) (#18382)

Motivation:

Port of #18331 to 5.0.

HttpResponseStatus only rejected CR and LF in the reason phrase. Other
control characters (NUL, VT, FF, ...) and DEL were still accepted when
parsing a response status line and written verbatim to the wire by
HttpResponseEncoder. Lenient downstream parsers may treat these as line
separators (response splitting / desync) and C-string based parsers may
truncate at NUL. RFC 9110 defines the reason-phrase as *( HTAB / SP /
VCHAR / obs-text ).

Modification:

Cherry-pick of aa30b7a from 4.2. The only conflict was in
HttpResponseDecoderTest, where `testInvalidHeaders0` declares `throws
Exception` on 5.0; the new tests were adjusted accordingly.

Result:

A response with control characters (other than HTAB) or DEL in its
reason phrase is now rejected by the decoder instead of being accepted
and re-encoded verbatim.

Potentially breaking: this adds stricter validation by default; reason
phrases containing such characters that were previously accepted are now
rejected.

Co-authored-by: 秦利斌 <[email protected]>
He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
Keep constructed status reasons within the HTTP/1 reason-phrase grammar.
The test suite must also compile where generated case-class copy methods
inherit constructor visibility, including Scala 3 and Scala next.

Modification:
Validate concrete status constructors, preserve legal bytes, cover public
factories, and document unknown-status parsing behavior. Remove test calls
to inaccessible generated copy methods while retaining public factory
coverage. Keep parser and validation behavior unchanged by this CI fix.

Result:
The original construction-time validation remains intact. Tests no longer
rely on case-class copy methods that are not public across Scala versions.
The separate review question about parser behavior remains unresolved.

Tests:
- git diff --check: passed.
- Static check: no generated copy calls remain in ResponseRendererSpec;
  existing public factory coverage and imports are retained.
- Scala compilation, tests, MiMa and formatting were not run for this
  revision: a working full JDK is unavailable. Prior-head reported passes
  are not evidence that this revised commit passes.

References:
Refs apache#1452 and PJ Fanning review 5938963618.
Refs netty/netty#18331 and RFC 9112 section 4.
pjfanning pushed a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
Keep constructed status reasons within the HTTP/1 reason-phrase grammar.
The test suite must also compile where generated case-class copy methods
inherit constructor visibility, including Scala 3 and Scala next.

Modification:
Validate concrete status constructors, preserve legal bytes, cover public
factories, and document unknown-status parsing behavior. Remove test calls
to inaccessible generated copy methods while retaining public factory
coverage. Keep parser and validation behavior unchanged by this CI fix.

Result:
The original construction-time validation remains intact. Tests no longer
rely on case-class copy methods that are not public across Scala versions.
The separate review question about parser behavior remains unresolved.

Tests:
- git diff --check: passed.
- Static check: no generated copy calls remain in ResponseRendererSpec;
  existing public factory coverage and imports are retained.
- Scala compilation, tests, MiMa and formatting were not run for this
  revision: a working full JDK is unavailable. Prior-head reported passes
  are not evidence that this revised commit passes.

References:
Refs apache#1452 and PJ Fanning review 5938963618.
Refs netty/netty#18331 and RFC 9112 section 4.
pjfanning added a commit to apache/pekko-http that referenced this pull request Nov 18, 2026
* fix: validate custom HTTP response reason phrases

Motivation:
Keep constructed status reasons within the HTTP/1 reason-phrase grammar.
The test suite must also compile where generated case-class copy methods
inherit constructor visibility, including Scala 3 and Scala next.

Modification:
Validate concrete status constructors, preserve legal bytes, cover public
factories, and document unknown-status parsing behavior. Remove test calls
to inaccessible generated copy methods while retaining public factory
coverage. Keep parser and validation behavior unchanged by this CI fix.

Result:
The original construction-time validation remains intact. Tests no longer
rely on case-class copy methods that are not public across Scala versions.
The separate review question about parser behavior remains unresolved.

Tests:
- git diff --check: passed.
- Static check: no generated copy calls remain in ResponseRendererSpec;
  existing public factory coverage and imports are retained.
- Scala compilation, tests, MiMa and formatting were not run for this
  revision: a working full JDK is unavailable. Prior-head reported passes
  are not evidence that this revised commit passes.

References:
Refs #1452 and PJ Fanning review 5938963618.
Refs netty/netty#18331 and RFC 9112 section 4.

* Drop invalid reason characters when parsing responses

Motivation:
With reason validation in the status constructors, an HTTP/1 response with
an unregistered status code and a control character in its reason phrase
failed at message start. RFC 9112 section 4 says a client SHOULD ignore
the reason-phrase content, so the reason should not make the response
unusable.

Modification:
Remove control characters other than HTAB, and DEL, from the received
reason before building the custom status. Update the parser test and the
http-model docs accordingly. Application-constructed statuses are still
validated.

Result:
Responses from servers with sloppy reason phrases still parse; the status
code and the remaining reason text are kept.

Tests:
- sbt "http-core/testOnly ...ResponseParserCRLFSpec ...ResponseParserLFSpec ...ResponseRendererSpec": 111 passed

References:
Refs #1452 review

---------

Co-authored-by: PJ Fanning <[email protected]>
hyperxpro pushed a commit to AsyncHttpClient/async-http-client that referenced this pull request Nov 21, 2026
## Summary

- Upgrades Netty from 4.2.20.Final to
[4.2.21.Final](https://github.com/netty/netty/releases/tag/netty-4.2.21.Final).
It mainly reverts a build mistake in 4.2.20: Netty's native libraries
for x86_64 and aarch64 required glibc 2.33. AHC declares the native
epoll and io_uring jars at its Netty version, and when they do not load,
it falls back to NIO, silently unless `useNativeTransport` is set. On
4.2.20 that would happen on systems with an older glibc, such as RHEL 8
or Ubuntu 20.04. AHC 3.0.14 used Netty 4.2.18, so no AHC release has
4.2.20.
- 4.2.21 also fixes `ZstdDecoder` and `ZstdDecompressor` at a
non-positive `io.netty.compression.defaultMaxForwardBytes`
(netty/netty#18289). This PR drops AHC's workarounds for that bug, so
zstd now waits for demand at any value of the property, like br and
snappy. A zero or negative value of the property now needs Netty 4.2.21
or later.

## Change

- **Netty 4.2.21.Final.**
- **Drop the `ZstdDecoder` replacement from #2375.** At a non-positive
value of the property, `Http1ContentDecompressor` replaced the
`ZstdDecoder` that `HttpContentDecompressor` creates with one whose
buffers hold `MAX_PART_SIZE`, because Netty's decoder handed on an empty
body at 0 and failed below it.
- **Drop the zstd guard from #2362.** At such a value, zstd went to
`HttpContentDecompressor` instead of `PullDecompression`, because
Netty's `ZstdDecompressor` handed out nothing at 0 while reporting more
output. It now takes the pull path there too:
  - it waits for demand;
  - parts are at most 64 KiB;
  - the size limit applies;
- a truncated stream fails with `Truncated zstd stream` instead of
ending quietly.
- **Docs:** the README and the Javadoc of
`ResponseBodyControl.suspend()` and of `Http1ContentDecompressor` no
longer make an exception for zstd. The README and `suspend()` say
instead that a zero or negative value of the property needs Netty 4.2.21
or later. With Netty 4.2.17 to 4.2.20, zstd responses then fail at a
negative value, and at 0 they never end and keep the event loop busy, as
Netty's `ZstdDecompressor` hands out empty buffers while it reports more
output. `MAX_FORWARD_BYTES` is private, since only
`Http1ContentDecompressor` uses it now.
- **Test:** `Http1ContentDecompressorForwardThresholdTest` runs with the
property at 0 and -1 in a fresh JVM. It now also checks zstd while
suspending after every part (one part per resume, none larger than
`MAX_PART_SIZE`) and a truncated zstd body (it fails, and nothing is
left allocated).

## Notes

- With the property at its default (64 KiB), nothing changes for zstd.
- Other changes in 4.2.21 that touch AHC's paths:
- Netty now also rejects control characters such as NUL and ESC, and
DEL, in a response's reason phrase (netty/netty#18331). CR and LF were
already rejected; HTAB is still allowed.
  - `SslHandler` changes: netty/netty#18253, #18323, #18363 and #18406.
  
  AHC's tests pass without changes.

## AI disclosure

Claude Code on behalf of Matthias Kurz. The commit includes
`Co-Authored-By` per `AGENTS.md`.

## Test plan

- [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11: 2,098
tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping
flags were used.
- [x] With the README and Javadoc change from review (`5fd35bad8`), the
same `clean verify`: 2,098 tests, 0 failures, 0 errors, 22 skipped;
Revapi passed. Docker was not running, so the 11 Testcontainers proxy
tests skipped themselves; they ran and passed in the runs above, on the
same code.
- [x] The version change alone, without the other changes, passes the
same `clean verify`: 2,098 tests, 0 failures.
- [x] The extended test fails where it should:
- with the guard put back, at 0 and -1: "the suspended zstd body did not
wait for demand after its first part";
- without the workarounds on Netty 4.2.20: at 0, the check hangs until
its 60 s timeout; at -1, it fails with `IllegalArgumentException:
initialCapacity : -1`.
- [x] The `Http1ContentDecompressor*Test`,
`Http2ContentDecompressorTest`, `Http1Decompression*Test` and
`ResponseBodyControlTest` classes: 142 tests, 0 failures.
- [x] Merged with #2394 (`ef18b0b68`): no conflicts; the same classes,
203 tests, 0 failures; `clean verify` on JDK 11, 2,159 tests, 0
failures, 0 errors, 11 skipped; Revapi passed.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ikpil added a commit to ikpil/Netty.NET that referenced this pull request Nov 29, 2026
…son phrases (netty/netty#18331)

Motivation:

HttpResponseStatus only rejected CR and LF in the reason phrase. Other
control characters (NUL, VT, FF, ...) and DEL were still accepted when
parsing a response status line and written verbatim to the wire by
HttpResponseEncoder. Lenient downstream parsers may treat these as line
separators (response splitting / desync) and C-string based parsers may
truncate at NUL. This closes the sibling gap of the request line
hardening: RFC 9110 defines the reason-phrase as
*( HTAB / SP / VCHAR / obs-text ).

Modification:

Reject every control character except HTAB, and DEL, in the
HttpResponseStatus reason phrase. HTAB and SP remain legal.

Result:

A response with control characters in its reason phrase is now rejected
by the decoder instead of being accepted and re-encoded verbatim.

Upstream-Commit: netty/netty@aa30b7a
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