Skip to content

Require CRLF after each chunk of a response body - #384

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/chunk-terminator
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/chunk-terminator

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #378.

read_chunked read the two bytes after each chunk and did not check them. 5\r\nhelloXX was accepted as the body hello, and XX was discarded. Those bytes can be the start of another response left on a keep-alive connection.

The two bytes now have to be CRLF. Anything else raises Net::HTTPBadResponse (wrong chunk terminator). A normal chunked body is unchanged.

Before the change, 5\r\nhelloXX0\r\n\r\n produced the body hello. After it, reading that body raises Net::HTTPBadResponse: wrong chunk terminator: "XX". A chunk that ends with CRLF still returns hello.

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

A chunk followed by other bytes was accepted and those bytes were
discarded.
The two bytes after chunk data were read and ignored. They have to be
CRLF; anything else 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.

Chunk terminators are consumed without validation, allowing response-queue desync on keep-alive connections

1 participant