h1_validate_connect_authority() checks that the authority of a CONNECT
request contains a non-empty port, but it doesn't check the host part. So
"CONNECT :443 HTTP/1.1" was accepted and forwarded with or without a Host
header, and with "Host: :443" the Host header was even normalized to an
empty value. Such a target is invalid (RFC9112#3.2.3 requires a
uri-host). Let's reject it.
This was introduced by commit
3f5fbe940 ("BUG/MEDIUM: h1: Improve authority
validation for CONNCET request") in 2.7. It should be backported as far as
2.8.
-varnishtest "H1 CONNECT requests without Host header"
+varnishtest "H1 CONNECT requests without Host header or with an empty host"
# A CONNECT request without Host header must get a Host header built from its
-# authority so that host-based rules apply to it.
+# authority so that host-based rules apply to it. An authority with an empty
+# host is rejected.
feature ignore_unknown_macro
expect resp.status == 200
expect resp.http.x-host == "www.example.com:8443"
} -run
+
+client c5 -connect ${h1_fe1_sock} {
+ txreq -req CONNECT -url ":443" -nohost
+ rxresp
+ expect resp.status == 400
+} -run
if (!istlen(uri_port))
goto invalid_authority;
uri_host.len -= (istlen(uri_port) + 1);
+ if (!istlen(uri_host))
+ goto invalid_authority;
if (!host_hdr || !isttest(*host_hdr))
goto end;