]> git.kaiwu.me - haproxy.git/commit
BUG/MAJOR: htx: Check the header/trailer length limits when one is updated
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 17 Sep 2026 06:44:05 +0000 (08:44 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 18 Sep 2026 15:05:18 +0000 (17:05 +0200)
commit89f19bea8c1e05947d206a38883d2107bc5fd824
tree2160254ab36d1ecdad6fc02174cf32f934932050
parenteaec3e46387c77dd2e7a490d116fe753dab6021d
BUG/MAJOR: htx: Check the header/trailer length limits when one is updated

The name and the value lengths of a header or a trailer are respectively
encoded on 8 and 20 bits in the block descriptor. So the name must not
exceed 255 bytes and the value must not exceed 1048575 bytes. This is
properly tested when a header or a trailer is added, since commit 3b69886f7
("BUG/MAJOR: htx: fix missing header name length check in
htx_add_header/trailer"). But no test was performed when one is updated.

htx_replace_blk_value(), used to update a part of a header or a trailer
value, may grow it above the limit. And htx_replace_header(), used to
replace a full header, does not check its arguments at all. In both cases,
the length silently overflows on the block type, changing it. For instance,
a HDR block becomes an EOH block while its value length wraps to a small
value.

Only the value length limit is reachable from the configuration, via a
"replace-header" or a "replace-value" rule, and only if "tune.bufsize" was
set above 1MB, because the block must first fit in the buffer. In that case,
a client sending a large enough header is enough to hit the issue.

So, perform the same tests than those performed when a header or a trailer
is added, instead of corrupting the message. In addition, a BUG_ON() was
added in htx_change_blk_value_len() and htx_set_blk_value_len() to catch any
other caller missing the test.

Reported by: Adam Crawford

This patch must be backported to all stable versions.
include/haproxy/htx.h
reg-tests/http-rules/replace_header_limits.vtc [new file with mode: 0644]
src/htx.c