BUG/MEDIUM: h1/h2/h3: reject forbidden chars in the Host header field
authorWilly Tarreau <w@1wt.eu>
Fri, 16 May 2025 12:58:52 +0000 (14:58 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 2 Jun 2025 14:20:37 +0000 (16:20 +0200)
commit38ef948e754e4cab938f219349642c89cf0a79e6
treed5e85cb827d5b1f9ea2c30cad2747b3aa7ceae0f
parent479befa356966c12a0a0ead74971750de4ac4499
BUG/MEDIUM: h1/h2/h3: reject forbidden chars in the Host header field

In continuation with 9a05c1f574 ("BUG/MEDIUM: h2/h3: reject some
forbidden chars in :authority before reassembly") and the discussion
in issue #2941, @DemiMarie rightfully suggested that Host should also
be sanitized, because it is sometimes used in concatenation, such as
this:

    http-request set-url https://%[req.hdr(host)]%[pathq]

which was proposed as a workaround for h2 upstream servers that require
:authority here:

    https://www.mail-archive.com/haproxy@formilux.org/msg43261.html

The current patch then adds the same check for forbidden chars in the
Host header, using the same function as for the patch above, since in
both cases we validate the host:port part of the authority. This way
we won't reconstruct ambiguous URIs by concatenating Host and path.

Just like the patch above, this can be backported afer a period of
observation.

(cherry picked from commit df00164fdd98d15e832daad34fb23249083bfb9c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/h1.c
src/h2.c
src/h3.c