Skip to content

Ignore Content-Length when sending a chunked request body - #369

Merged
mame merged 1 commit into
ruby:masterfrom
frandle331-yh:ignore-content-length-when-chunked
Nov 26, 2026
Merged

mame merged 1 commit into
ruby:masterfrom
frandle331-yh:ignore-content-length-when-chunked

Conversation

@frandle331-yh

Copy link
Copy Markdown
Contributor

Sending both Content-Length and Transfer-Encoding: chunked on a request is a request-smuggling primitive (RFC 9112 §6.1): a desyncing intermediary can frame the two differently. Net::HTTP lets a caller set both, and on the body-stream and chunked multipart/form-data paths it then wrote both headers on the wire.

This drops Content-Length whenever the body is sent chunked, so only the chunk framing is emitted (the plain-body path already removed Transfer-Encoding). This matches the behavior agreed with the net-http maintainer in the report below.

Reported via HackerOne #3777378 (Reported-by: Hierax).

Includes a regression test: a chunked request with a caller-set Content-Length must not put Content-Length on the wire (it fails before this change, passes after).

Sending both Content-Length and Transfer-Encoding: chunked on a request is a request-smuggling primitive (RFC 9112 6.1): a desync proxy may frame the two differently. When a caller sets both, Net::HTTP now drops Content-Length and sends only the chunked framing (in the body-stream and multipart/form-data chunked paths; the plain-body path already removed Transfer-Encoding).

Reported at https://hackerone.com/reports/3777378

@mame mame left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mame
mame merged commit 065b082 into ruby:master Nov 26, 2026
26 checks passed
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.

2 participants