Make Content-Length handling strict - #324
Merged
Merged
Conversation
kou
force-pushed
the
strict-response-content-length
branch
2 times, most recently
from
August 25, 2026 03:04
7b0e9b6 to
22238b9
Compare
kou
commented
Aug 25, 2026
Comment on lines
-212
to
+214
| @headers['Transfer-Encoding'] = 'chunked' | ||
| self['Transfer-Encoding'] = 'chunked' | ||
| else | ||
| @headers['Content-Length'] = @body.bytesize.to_s | ||
| self['Content-Length'] ||= @body.bytesize.to_s |
Member
Author
There was a problem hiding this comment.
We must use self[]= not @headers[]= here because self[]= uses downcase.
Member
|
An empty
|
`Content-Length` value must have only digits. See also RFC 9110 Section 8.6: https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6 Content-Length = 1*DIGIT The current implementation accepts garbage before/after digits such as `abc5` and `5abc`. This rejects these invalid values. But this accepts same values in one `Content-Length` Content-Length: 5, 5 and in multiple `Content-Length`es: Content-Length: 5 Content-Length: 5 This is for the following part in the RFC: https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6-13 > Likewise, a sender MUST NOT forward a message with a Content-Length > header field value that does not match the ABNF above, with one > exception: a recipient of a Content-Length header field value > consisting of the same decimal value repeated as a comma-separated > list (e.g, "Content-Length: 42, 42") MAY either reject the message > as invalid or replace that invalid field value with a single > instance of the decimal value, since this likely indicates that a > duplicate was generated or combined by an upstream message > processor.
kou
force-pushed
the
strict-response-content-length
branch
from
August 25, 2026 07:51
22238b9 to
2635a7e
Compare
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Aug 26, 2026
(ruby/net-http#324) `Content-Length` value must have only digits. See also RFC 9110 Section 8.6: https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6 Content-Length = 1*DIGIT The current implementation accepts garbage before/after digits such as `abc5` and `5abc`. This rejects these invalid values. But this accepts same values in one `Content-Length` Content-Length: 5, 5 and in multiple `Content-Length`es: Content-Length: 5 Content-Length: 5 This is for the following part in the RFC: https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6-13 > Likewise, a sender MUST NOT forward a message with a Content-Length > header field value that does not match the ABNF above, with one > exception: a recipient of a Content-Length header field value > consisting of the same decimal value repeated as a comma-separated > list (e.g, "Content-Length: 42, 42") MAY either reject the message > as invalid or replace that invalid field value with a single > instance of the decimal value, since this likely indicates that a > duplicate was generated or combined by an upstream message > processor. ruby/net-http@23e859e92e
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.
Content-Lengthvalue must have only digits.See also RFC 9110 Section 8.6:
https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6
The current implementation accepts garbage before/after digits such as
abc5and5abc.This rejects these invalid values.
But this accepts same values in one
Content-Lengthand in multiple
Content-Lengthes:This is for the following part in the RFC:
https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6-13