]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mux-h1: Remove "Upgrade:" header for requests with payload
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Sep 2021 07:52:51 +0000 (09:52 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 10 Sep 2021 07:17:51 +0000 (09:17 +0200)
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
src/mux_h2.c

index 70e4b2cb01be7df5ac7a1c95b708f40b53a1ced4..6ea19d265f2d2f3f7b8f0f8ce2d062741a3656cf 100644 (file)
@@ -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;
index 5fd492a11dec31c7f05d4852663af816c74462f0..45506c65d0c045a47561a92eb6a9aa18cf47df83 100644 (file)
@@ -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
                                 *