Repository navigation
Validate custom HTTP response reason phrases - #1452
Merged
Merged
Conversation
pjfanning
reviewed
Nov 17, 2026
pjfanning
left a comment
Member
There was a problem hiding this comment.
Thanks. Validating in the constructors keeps the rule in one place, and the error message doesn't echo the invalid reason, which is good. A few points:
- CI fails on Scala 3 and next.
ResponseRendererSpeccallsStatusCodes.Continue.copy(199)(...),StatusCodes.OK.copy(299)(...)etc. These case classes haveprivate[StatusCodes]constructors, and on Scala 3 that makes the generatedcopyprivate too (E173 ... private[StatusCodes] method copy can only be accessed from object StatusCodes). So on Scala 3copyisn't a public way to construct these at all, and thecopycases need to go (or be limited to 2.13). - Failing to parse responses because of the reason phrase. With this change, an HTTP/1 response with an unregistered status code and a control character in its reason phrase now fails at message start in the client parser. RFC 9112 §4 says a client SHOULD ignore the reason-phrase content, so failing the whole response over it is the opposite of what's recommended. Rejecting invalid reasons when the application builds a status is reasonable, but on the parse path I'd sanitise instead: fall back to an empty or default reason, or drop the offending characters, so a sloppy server's status line doesn't make the response unusable.
- Docs. The paragraph added to
http-model.mdis fine for the custom-status API, but if point 2 changes, the sentence about rejecting invalid reasons when parsing needs updating.
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.
He-Pin
force-pushed
the
fix/status-reason-validation
branch
from
November 17, 2026 15:46
8920091 to
fed72dd
Compare
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.
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 apache#1452 review
pjfanning
force-pushed
the
fix/status-reason-validation
branch
from
November 17, 2026 18:39
fed72dd to
b3c164c
Compare
Member
|
I rebased this onto |
This was referenced Nov 19, 2026
pjfanning
added a commit
that referenced
this pull request
Nov 20, 2026
Motivation: A status code reason is rendered as-is into the HTTP/1 status line, so a custom reason containing CR or LF could inject extra lines into a response. Modification: Validate the reason in every StatusCode constructor against the RFC 9112 section 4 reason-phrase grammar (HTAB, SP, VCHAR, obs-text) and throw IllegalArgumentException otherwise. When parsing a response with an unregistered status code, drop control characters and DEL from the received reason instead of failing the response. Result: Application-constructed status codes can't carry characters that break HTTP/1 framing, and responses with sloppy reason phrases still parse. Tests: - ResponseParserSpec, ResponseRendererSpec (backport of #1452) References: Backport of #1452 (b2f6e58) Co-authored-by: He-Pin(kerr) <[email protected]>
pjfanning
added a commit
that referenced
this pull request
Nov 20, 2026
Motivation: A status code reason is rendered as-is into the HTTP/1 status line, so a custom reason containing CR or LF could inject extra lines into a response. Modification: Validate the reason in every StatusCode constructor against the RFC 9112 section 4 reason-phrase grammar (HTAB, SP, VCHAR, obs-text) and throw IllegalArgumentException otherwise. When parsing a response with an unregistered status code, drop control characters and DEL from the received reason instead of failing the response. Result: Application-constructed status codes can't carry characters that break HTTP/1 framing, and responses with sloppy reason phrases still parse. Tests: - ResponseParserSpec, ResponseRendererSpec (backport of #1452) References: Backport of #1452 (b2f6e58) Co-authored-by: He-Pin(kerr) <[email protected]>
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
Custom status reasons currently accept characters outside the HTTP/1 reason-phrase grammar and can pass them to the status-line renderer. Keep constructed status objects representable as a valid reason phrase, rather than relying on each caller to validate its input.
This is model/output validation informed by Netty's related change. It does not claim a demonstrated downstream exploit.
Modification
obs-textbyte range. Reject other control characters, DEL, null and characters above0xff, which the existing byte renderer cannot represent without truncation.Result
Constructed status objects cannot carry an invalid reason phrase into HTTP/1 rendering. Parsing standard or registered status codes continues to use the registered reason. When parsing a response with an unregistered status code, control characters (other than HTAB) and DEL are dropped from the received reason instead of failing the response, following RFC 9112 section 4's advice that clients ignore the reason phrase. Applications that construct a status with an invalid reason now receive
IllegalArgumentException.Tests
The results below are historical validation. The latest compiler-only follow-up removes six calls to inaccessible private generated
copymethods from tests to address Scala 3/next E173 errors; it makes no production change. Current test coverage uses the public Scala and Java factories and does not claim generated-copy coverage. The parser behavior was later changed to drop invalid characters from a received reason (commit b3c164c); project CI passed on the merged revision.http-core / mimaReportBinaryIssuespassed.git diff --checkpassed.javafmtAllanddocs / paradoxwere blocked by the unrelatedhttp2-testsh2spec dependency download; scoped core checks passed. No full-suite or CI run was performed for this change.References
Refs netty/netty#18331
Reason-phrase grammar: https://www.rfc-editor.org/rfc/rfc9112.html#section-4