Repository navigation
[1.5.x] Validate custom HTTP response reason phrases (#1452) - #1514
Merged
Merged
Conversation
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 apache#1452) References: Backport of apache#1452 (b2f6e58)
He-Pin
approved these changes
Nov 20, 2026
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:
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:
References:
Backport of #1452 (b2f6e58)