]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1: Reject requests if the authority does not match the header host
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Oct 2019 11:34:22 +0000 (13:34 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 14 Oct 2019 20:28:50 +0000 (22:28 +0200)
As stated in the RCF7230#5.4, a client must send a field-value for the header
host that is identical to the authority if the target URI includes one. So, now,
by default, if the authority, when provided, does not match the value of the
header host, an error is triggered. To mitigate this behavior, it is possible to
set the option "accept-invalid-http-request". In that case, an http error is
captured without interrupting the request parsing.

src/h1.c

index 7e7eaa064a175fb3882141e2ac9a4b624ae6e769..83afb14ebc5c50fb739a96def36c89e281e716a2 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -834,8 +834,20 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                                        }
                                }
                                else if (isteqi(n, ist("host"))) {
-                                       if (host_idx == -1)
+                                       if (host_idx == -1) {
+                                               struct ist authority;
+
+                                               authority = http_get_authority(sl.rq.u, 1);
+                                               if (authority.len && !isteqi(v, authority)) {
+                                                       if (h1m->err_pos < -1) {
+                                                               state = H1_MSG_HDR_L2_LWS;
+                                                               goto http_msg_invalid;
+                                                       }
+                                                       if (h1m->err_pos == -1) /* capture the error pointer */
+                                                               h1m->err_pos = ptr - start + skip; /* >= 0 now */
+                                               }
                                                host_idx = hdr_count;
+                                       }
                                        else {
                                                if (!isteqi(v, hdr[host_idx].v)) {
                                                        state = H1_MSG_HDR_L2_LWS;