]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: stconn: Only forward kip hint on streams committed to forward data
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 19 Nov 2026 08:00:00 +0000 (09:00 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 23 Nov 2026 13:49:44 +0000 (14:49 +0100)
commita32e3c8bb84e19a3b3b3e1530e3ad8b8f2d7e3f9
tree27cef1e361bcfb4f2a095c5b14e75ce69f10a282
parent8236299dee6a32f22fb825e749692b6588b50a38
BUG/MEDIUM: stconn: Only forward kip hint on streams committed to forward data

The <kip> hint of a sedesc is the payload length the producer endpoint
estimates it will emit. It is forwarded to the <kop> hint of the opposite
sedesc by sc_ep_fwd_kip(), so the consumer endpoint can use it as an
optimization, for instance the H1 mux to announce a chunk size covering the
whole payload at once.

But <kip> could be set by the producer on the data it demultiplexes, before
the app layer has a chance to see it. In particular, when data filters are
registered on the channel, flt_http_payload() resets <kip> after each pass,
because the filters may alter or drop any part of the payload. But in the
meantime, an I/O callback may already have moved the hint to the opposite
side: the consumer then uses a stale <kop> value, and the data it emits may
not match what this value announces.

This is how the H1 mux could be led to announce a chunk smaller than the
data sent with it, and to emit the remaining bytes without any chunk
framing, making an HTTP/1 server process a part of the request payload as
another request (request smuggling).

The root of the issue is that <kip>/<kop> are hints on data which were
not evaluated by the app layer yet, but they may be consumed as if they
were. <kop> is a minimal guarantee on the output payload: when it is
set, at least this size will be forwarded. It is only safe to feed it
with <kip> once the app layer committed to forward the data as-is.

This patch introduced a safe version of sc_ep_fwd_kip(),
sc_ep_fwd_kip_when_committed(), which only forwards the hint when the
producer channel is configured to forward data indefinitely (to_forward ==
CHN_INFINITE_FORWARD). This is the only case where the app layer committed
to forward everything, without any alteration: http_wait_request_body() and
http_wait_for_response_body() set the infinite forwarding only when no data
filter is registered on the channel. Otherwise <kop> stays null and the
consumer endpoints fall back to their conservative behavior (the H1 mux
announces the size of the data it emits).

When the app layer is not committed yet, <kip> is reset instead of being
kept for later. Until the infinite forwarding is reached, data may be
forwarded and emitted by the consumer with a null <kop>, while <kip> still
accounts for them, because it is only decremented when forwarded. Moving
it later would then set <kop> higher than the remaining payload, and the
H1 mux would announce a chunk bigger than the data left to send. Resetting
it keeps <kop> conservative: lower than the remaining payload, never
higher.

Thanks to Hyunho Seo for the issue analysis.

This patch must be backported as far as 3.3.
include/haproxy/stconn.h
src/applet.c
src/stconn.c