Skip to content

[1.5.x] Validate custom HTTP response reason phrases (#1452) - #1514

Merged
pjfanning merged 1 commit into
apache:1.5.xfrom
pjfanning:backport-1452-1.5.x
Nov 20, 2026
Merged

pjfanning merged 1 commit into
apache:1.5.xfrom
pjfanning:backport-1452-1.5.x

Conversation

@pjfanning

Copy link
Copy Markdown
Member

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:

  • http-core/testOnly ResponseParserCRLFSpec ResponseParserLFSpec ResponseRendererSpec: 108 passed (Scala 2.13)
  • http-core/mimaReportBinaryIssues: passed

References:
Backport of #1452 (b2f6e58)

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)
@pjfanning pjfanning added this to the 1.5.0 milestone Nov 19, 2026
@pjfanning
pjfanning merged commit 2d83936 into apache:1.5.x Nov 20, 2026
10 checks passed
@pjfanning
pjfanning deleted the backport-1452-1.5.x branch November 20, 2026 07:19
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.

2 participants