Skip to content

Treat a bad response header as a protocol error - #383

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/response-header-errors
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/response-header-errors

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #379.

Response headers were stored with the request validators. A value over 65536 bytes, a name over 1024 bytes, or a control character in a name raised ArgumentError from Net::HTTPResponse.read_new. That is not a Net::HTTP error, so a rescue of Net::HTTPBadResponse does not catch it. The 64 KiB cap also rejected a legitimate large response header. The total response header is already limited to 1 MiB while it is read.

A response field may now be as long as that 1 MiB budget. A name or value the validators still reject is raised as Net::HTTPBadResponse with the same message. Requests still use the 64 KiB value cap and still raise ArgumentError.

Before the change, a 65537-byte X-Token raised ArgumentError: header X-Token has too long field value: 65537 bytes (limit 65536), and a 1025-byte name raised ArgumentError. After it, the value is kept (65537 bytes) and the long name raises Net::HTTPBadResponse.

ruby -Ilib:test/lib -rhelper test/net/http/test_httpresponse.rb: 52 tests, 113 assertions, 0 failures.
ruby -Ilib:test/lib -rhelper test/net/http/test_httpheader.rb: 41 tests, 202 assertions, 0 failures.

A response value longer than the request field limit was rejected, and
a bad response header name raised ArgumentError.
Response fields went through the request validators, so a long value
raised ArgumentError and a 64 KiB cap rejected ordinary large headers.
A response may use the response header budget, and a name or value the
validators still reject is Net::HTTPBadResponse.

This branch has not been deployed

No deployments
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.

Response headers are checked with request-side limits and raise ArgumentError instead of a Net::HTTP protocol error

1 participant