Skip to content

Reject a response that ends inside the headers - #385

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/truncated-headers
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/truncated-headers

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #377.

Header lines were read with ignore_eof set. When the peer closed the connection before the blank line, the partial buffer was treated as the end of the headers. A cut after Content-Type returned a 200 whose later headers and body were missing, and a line cut mid-value was stored as that value (malic). http.ignore_eof = false does not apply to the header section.

The header read no longer ignores EOF. EOF before the blank line raises Net::HTTPBadResponse. A response that includes the blank line is unchanged. A connection that closes before any status line is still EOFError.

Before the change, HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n (no blank line) was a 200 with that one header, and X-Classification: malic with no newline was stored as malic. After it, both raise Net::HTTPBadResponse: end of file reached before the end of the headers. A response that ends with the blank line still returns 200 and X-Classification: malicious.

ruby -Ilib:test/lib -rhelper test/net/http/test_httpresponse.rb: 51 tests, 112 assertions, 0 failures.

A response cut before the blank line was accepted, including a header
line that never finished.
Header lines were read with ignore_eof, so a connection that closed
before the blank line was a finished response. That read now fails, and
the failure 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.

Truncated HTTP responses are accepted as complete, letting a connection-cutter hide headers and bodies (fail-open)

1 participant