From 52a5ec2d18d610efcfd54da1856d1a4e6099d866 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 9 Sep 2021 09:52:51 +0200 Subject: [PATCH] BUG/MEDIUM: mux-h1: Remove "Upgrade:" header for requests with payload Instead of returning a 501-Not-implemented error when "Ugrade:" header is found for a request with a payload, the header is removed. This way, the upgrade is disabled and the request is still sent to the server. It is required because some frameworks seem to try to perform H2 upgrade on every requests, including POST ones. The h2 mux was slightly fixed to convert Upgrade requests to extended connect ones only if the rigth HTX flag is set. This patch should fix the issue #1381. It must be backported to 2.4. --- src/h1_htx.c | 11 +++++++++++ src/mux_h2.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/h1_htx.c b/src/h1_htx.c index 70e4b2cb0..6ea19d265 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -178,7 +178,18 @@ static int h1_postparse_req_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx h1m->curr_len = h1m->body_len = 0; } + flags = h1m_htx_sl_flags(h1m); + if ((flags & (HTX_SL_F_CONN_UPG|HTX_SL_F_BODYLESS)) == HTX_SL_F_CONN_UPG) { + int i; + + for (i = 0; hdrs[i].n.len; i++) { + if (isteqi(hdrs[i].n, ist("upgrade"))) + hdrs[i].v = IST_NULL; + } + h1m->flags &=~ H1_MF_CONN_UPG; + flags &= ~HTX_SL_F_CONN_UPG; + } sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth, uri, vsn); if (!sl || !htx_add_all_headers(htx, hdrs)) goto error; diff --git a/src/mux_h2.c b/src/mux_h2.c index 5fd492a11..45506c65d 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -5288,7 +5288,7 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx) continue; /* Convert connection: upgrade to Extended connect from rfc 8441 */ - if (isteqi(list[hdr].n, ist("connection"))) { + if ((sl->flags & HTX_SL_F_CONN_UPG) && isteqi(list[hdr].n, ist("connection"))) { /* rfc 7230 #6.1 Connection = list of tokens */ struct ist connection_ist = list[hdr].v; do { @@ -5306,7 +5306,7 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx) } while (istlen(connection_ist)); } - if (isteq(list[hdr].n, ist("upgrade"))) { + if ((sl->flags & HTX_SL_F_CONN_UPG) && isteq(list[hdr].n, ist("upgrade"))) { /* rfc 7230 #6.7 Upgrade = list of protocols * rfc 8441 #4 Extended connect = :protocol is single-valued *