BUG/MEDIUM: h2: give :authority precedence over Host
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Aug 2021 13:39:13 +0000 (15:39 +0200)
committerRaspbian forward porter <root@raspbian.org>
Thu, 9 Sep 2021 16:57:32 +0000 (17:57 +0100)
commit79736c77d2203b12e1ea327cc052c4c48f1da95f
treea0911fe2c8c3f3bf7c48703fa553225c1eb7f28c
parent8f1bfce1f8a9fde7a02112331e33afbec6ffd8eb
BUG/MEDIUM: h2: give :authority precedence over Host

The wording regarding Host vs :authority in RFC7540 is ambiguous as it
says that an intermediary must produce a host header from :authority if
Host is missing, but doesn't say anything regarding the possibility that
Host and :authority differ, which leaves Host with higher precedence
there. In addition it mentions that clients should use :authority
*instead* of Host, and that H1->H2 should use :authority only if the
original request was in authority form. This leaves some gray area in
the middle of the chain for fully valid H2 requests arboring a Host
header that are forwarded to the other side where it's possible to
drop the Host header and use the authority only after forwarding to a
second H2 layer, thus possibly seeing two different values of Host at
a different stage. There's no such issue when forwarding from H2 to H1
as the authority is dropped only only the Host is kept.

Note that the following request is sufficient to re-normalize such a
request:

   http-request set-header host %[req.hdr(host)]

The new spec in progress (draft-ietf-httpbis-http2bis-03.html) addresses
this trouble by being a bit is stricter on these rules. It clarifies that
:authority must always be used instead of Host and that Host ought to be
ignored. This is much saner as it avoids to convey two distinct values
along the chain. This becomes the protocol-level equivalent of:

   http-request set-uri %[url]

So this patch does exactly this, which we were initially a bit reluctant
to do initially by lack of visibiility about other implementation's
expectations. In addition it slightly simplifies the Host header field
creation by always placing it first in the list of headers instead of
last; this could speed up the look up a little bit.

This needs to be backported to 2.0. The legacy code there is a bit
different but not too much, the code can be simplified to simply
omit host during the copy and continue.

Thanks to Tim Düsterhus for reporting that one.

(cherry picked from commit 872e672e17d3fd22dd9d11d94fd98bb6fdd9779c)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit ab811714690aae3388626d38682b31914729244d)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 00bd4df20c74d22bb057bd11acfc7befe201a7b3)
Signed-off-by: Willy Tarreau <w@1wt.eu>
Gbp-Pq: Name 2.2-0005-BUG-MEDIUM-h2-give-authority-precedence-over-Host.patch
src/h2.c