]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http-htx: Don't return error if authority is updated without changes
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 18 Feb 2020 10:02:21 +0000 (11:02 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 18 Feb 2020 10:19:57 +0000 (11:19 +0100)
When an Host header is updated, the autority part, if any, is also updated to
keep the both syncrhonized. But, when the update is performed while there is no
change, a failure is reported while, in reality, no update is necessary. This
bug was introduced by the commit d7b7a1ce5 ("MEDIUM: http-htx: Keep the Host
header and the request start-line synchronized").

This commit was pushed in the 2.1. But on this version, the bug is hidden
because rewrite errors are silently ignored. And because it happens when there
is no change, if the rewrite fails, noone notices it. But since the 2.2, rewrite
errors are now fatals by default. So when the bug is hit, a 500 error is
returned to the client. Without this fix, a workaround is to disable the strict
rewriting mode (see the "strict-mode" HTTP rule).

The following HTTP rule is a good way to reproduce the bug if a request with an
authority is received. In HTT2, it is pretty common.

    acl host_header_exists req.hdr(host) -m found
    http-request set-header host %[req.hdr(host)] if host_header_exists

This patch must be backported to 2.1 and everywhere the commit d7b7a1ce5 is
backported. It should fix the issue #494.

src/http_htx.c

index f2f0a0c18a862d638838e9abcb2b8fee1dd6ac0a..f6e224305f9c72b6f3f1b2a05beff7397e58ad88 100644 (file)
@@ -584,9 +584,13 @@ static int http_update_authority(struct htx *htx, struct htx_sl *sl, const struc
 
        uri = htx_sl_req_uri(sl);
        authority = http_get_authority(uri, 1);
-       if (!authority.len || isteq(host, authority))
+       if (!authority.len)
                return 0;
 
+       /* Don't update the uri if there is no change */
+       if (isteq(host, authority))
+               return 1;
+
        /* Start by copying old method and version */
        chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */
        meth = ist2(temp->area, HTX_SL_REQ_MLEN(sl));