Repository navigation
Validate response headers and protocol versions. - #74
Merged
Merged
Conversation
This was referenced Nov 7, 2026
Merged
1 of 4 tasks
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.
Summary
Headers::fromArray()(and every path through it:from(),fromMessage(),with(),mergedWith()) rejects a header name that ends in a line feed. The token pattern ended in$without theDmodifier, so"X-Trace\n"matched.HeaderNameandHeaderValue.Headersuses them directly, and the response uses them through the internalResponseField, the single validation point for every header that reaches a response.Headerablearguments of theResponsefactories,withHeader()andwithAddedHeader(). A name that is not an RFC 9110 token raisesHeaderNameIsInvalid, and a value with a control character other than horizontal tab (CR, LF and NUL included, per RFC 9110 section 5.5, RFC 9113 section 8.2.1 and RFC 9114 section 4.2) raisesHeaderValueIsInvalid. Both extendInvalidArgumentException, which is what PSR-7 asks ofwithHeader()andwithAddedHeader().HeaderIsConnectionSpecific:Connection,Keep-Alive,Proxy-Connection,Transfer-Encoding,Upgrade, andTEwith any value other thantrailers(names compared case-insensitively, theTEvalue trimmed and compared case-insensitively). HTTP/2 (RFC 9113 section 8.2.2) and HTTP/3 (RFC 9114 section 4.2) treat a message carrying one as malformed. The rule applies to responses only:Headersalso wraps incoming requests (Request::headers()) and outgoing client requests, where an HTTP/1.1Connection: keep-aliveis ordinary, so rejecting it there would break every request a server receives over HTTP/1.1.ProtocolVersionenum:1.0,1.1,2,3.withProtocolVersion()stores2.0and3.0as2and3, and raises the newProtocolVersionIsUnsupportedfor anything else. A response still starts on1.1, the PSR-7 convention.Responsefactories are static and never see the request, and the library ships no middleware that sits where both are in reach, so adding one only for this would be new surface. The README documents the path instead,->withProtocolVersion($request->getProtocolVersion()), which the closed set makes safe because a2.0fromSERVER_PROTOCOLis normalized and a malformed value is refused rather than written into the status line.Breaking changes and migration
Recommended release:
8.0.0(major). Each item below is input that used to pass and now throws, so a caller relying on it breaks at runtime.\ninHeaders::fromArray(),from(),fromMessage(),with()HeaderNameIsInvalidResponsefactories (Headerable),withHeader(),withAddedHeader()HeaderNameIsInvalidorHeaderValueIsInvalidfor a non-token name or a value with a control character other than tabConnection,Keep-Alive,Proxy-Connection,Transfer-Encoding,Upgradeon a responseHeaderIsConnectionSpecificTEwith a value other thantrailerson a responseHeaderIsConnectionSpecifictrailers.withProtocolVersion()with any string,''included (''used to mean1.1)ProtocolVersionIsUnsupportedunless1.0,1.1,2,2.0,3,3.01.1.withProtocolVersion('2.0')/('3.0')stored as given2/32/3.No public signature changes. The new public types are
HeaderIsConnectionSpecificandProtocolVersionIsUnsupported, bothInvalidArgumentExceptionandHttpException.Dependents:
tiny-blocks/http-error-handler,http-health-check,http-logging,http-query,skedli/http-authenticationandskedli/http-idempotencyall requiretiny-blocks/http^7.2, so each needs a release widening that constraint before a service can install8.0.0.Related issue
None.
Checklist
make reviewpasses.make testspasses.