# reference showing that each offending message is accepted by default.
#
# On the request side there is no server: the frontend replies itself and
-# reports the method, the header names it saw and the hex-encoded value of
-# header "foo", which reflect what remains after the checks ran in the H1
-# parser.
+# reports the method, the header names it saw, the hex-encoded value of
+# header "foo" and the full value of header "upgrade", which reflect what
+# remains after the checks ran in the H1 parser.
#
# On the response side, each profile's server first sends a valid response,
# then the offending ones, which must turn into 502 when the check is enabled.
http-hardening req-pld
reject-unexpected-request-payload on
+ http-hardening req-upg
+ reject-unexpected-request-upgrade on
+
defaults
mode http
http-reuse never
bind "fd@${req_cl0}" http-hardening cl0
bind "fd@${req_adv_meth}" http-hardening adv-meth
bind "fd@${req_pld}" http-hardening req-pld
- http-request return status 200 hdr x-meth "%[method]" hdr x-hdrs "%[req.hdr_names]" hdr x-foo "%[req.hdr(foo),hex]"
+ bind "fd@${req_upg}" http-hardening req-upg
+ http-request return status 200 hdr x-meth "%[method]" hdr x-hdrs "%[req.hdr_names]" hdr x-foo "%[req.hdr(foo),hex]" hdr x-upg "%[req.fhdr(upgrade)]"
# response side: one listener per server profile
listen res_off
rxresp
expect resp.status == 200
+ txreq -nouseragent -hdr "connection: upgrade" -hdr "upgrade: foo, websocket" -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-upg == "foo, websocket"
+
# T-E + C-L forces a close
txreq -nouseragent -req POST -nolen -hdr "content-length: 2" -hdr "transfer-encoding: chunked" -body "2\r\nok\r\n0\r\n\r\n"
rxresp
expect_close
} -run
+# only websocket and webtransport remain in the Upgrade header, which is
+# removed once empty, without rejecting the request.
+client c_req_upg -connect ${h1_req_upg_sock} {
+ txreq -nouseragent -nohost -hdr "connection: upgrade" -hdr "upgrade: websocket" -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-upg == "websocket"
+
+ txreq -nouseragent -nohost -hdr "connection: upgrade" -hdr "upgrade: WebTransport"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-upg == "WebTransport"
+
+ txreq -nouseragent -nohost -hdr "connection: upgrade" -hdr "upgrade: foo, websocket, bar/1" -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-upg == "websocket"
+
+ txreq -nouseragent -nohost -hdr "connection: upgrade" -hdr "upgrade: foo, bar/1"
+ rxresp
+ expect resp.status == 200
+ # "connection: upgrade" goes away with the Upgrade header
+ expect resp.http.x-upg == <undef>
+ expect resp.http.x-hdrs == <undef>
+} -run
+
#
# Responses
#
# and a rejected response causes a 502.
#
# On the request side the frontend replies itself and reports the method, the
-# header names it saw and the hex-encoded value of header "foo".
+# header names it saw and the hex-encoded value of header "foo". Extended
+# CONNECT requests (RFC8441) are passed to an HTTP/1 server instead, which
+# accepts the upgrade. For websocket, this server is a frontend of the same
+# instance which computes the Sec-WebSocket-Accept header that haproxy
+# verifies, as in websocket.vtc.
feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(3.5-dev10)'"
feature ignore_unknown_macro
} -run
} -start
+# extended CONNECT turned into an HTTP/1 upgrade, for the accepted protocols
+server s_upg_off {
+ rxreq
+ expect req.http.upgrade == "foo"
+ txresp -status 101 -hdr "connection: upgrade" -hdr "upgrade: foo"
+} -start
+
+server s_upg_ok {
+ rxreq
+ expect req.http.upgrade == "webtransport"
+ txresp -status 101 -hdr "connection: upgrade" -hdr "upgrade: webtransport"
+} -start
+
haproxy h1 -conf {
global
.if feature(THREAD)
http-hardening req-pld
reject-unexpected-request-payload on
+ http-hardening req-upg
+ reject-unexpected-request-upgrade on
+
defaults
mode http
http-reuse never
bind "fd@${req_pld}" proto h2 http-hardening req-pld
http-request return status 200 hdr x-meth "%[method]" hdr x-hdrs "%[req.hdr_names]" hdr x-foo "%[req.hdr(foo),hex]"
+ # extended CONNECT: one listener per server
+ listen req_upg_off
+ bind "fd@${req_upg_off}" proto h2 http-hardening off
+ server s ${s_upg_off_addr}:${s_upg_off_port} http-hardening off
+
+ listen req_upg_ok
+ bind "fd@${req_upg_ok}" proto h2 http-hardening req-upg
+ server s ${s_upg_ok_addr}:${s_upg_ok_port} http-hardening off
+
+ listen req_upg_ws
+ bind "fd@${req_upg_ws}" proto h2 http-hardening req-upg
+ server s ${h1_ws_srv_addr}:${h1_ws_srv_port} http-hardening off
+
+ # websocket server: returns a valid handshake response
+ frontend ws_srv
+ bind "fd@${ws_srv}" http-hardening off
+ capture request header sec-websocket-key len 128
+ http-request return status 200 hdr connection upgrade hdr upgrade websocket hdr sec-websocket-accept "%[capture.req.hdr(0),concat(258EAFA5-E914-47DA-95CA-C5AB0DC85B11,,),sha1,base64]"
+ http-after-response set-status 101 if { status eq 200 }
+
+ # the server is never reached
+ listen req_upg
+ bind "fd@${req_upg}" proto h2 http-hardening req-upg
+ server s 127.0.0.1:1 http-hardening off
+
# response side: one listener per server
listen s_off_us
bind "fd@${s_off_us}" proto h2 http-hardening off
} -run
} -run
+client c_req_upg_off -connect ${h1_req_upg_off_sock} {
+ txpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ rxsettings
+ expect settings.ack == true
+ } -run
+
+ stream 1 {
+ txreq -req CONNECT -scheme http -url / -hdr ":authority" "a" -hdr ":protocol" "foo" -nostrend
+ rxwinup
+ rxhdrs
+ expect resp.status == 200
+ } -run
+} -run
+
# without :authority, Host is the only source of the authority
client c_req_dup_host -connect ${h1_req_dup_host_sock} {
txpri
} -run
} -run
+# extended CONNECT is only accepted for websocket and webtransport
+client c_req_upg_ok -connect ${h1_req_upg_ok_sock} {
+ txpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ rxsettings
+ expect settings.ack == true
+ } -run
+
+ stream 1 {
+ txreq -req CONNECT -scheme http -url / -hdr ":authority" "a" -hdr ":protocol" "webtransport" -nostrend
+ rxwinup
+ rxhdrs
+ expect resp.status == 200
+ } -run
+} -run
+
+client c_req_upg_ws -connect ${h1_req_upg_ws_sock} {
+ txpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ rxsettings
+ expect settings.ack == true
+ } -run
+
+ stream 1 {
+ txreq -req CONNECT -scheme http -url / -hdr ":authority" "a" -hdr ":protocol" "websocket" -nostrend
+ rxwinup
+ rxhdrs
+ expect resp.status == 200
+ } -run
+} -run
+
+client c_req_upg -connect ${h1_req_upg_sock} {
+ txpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ rxsettings
+ expect settings.ack == true
+ } -run
+
+ stream 1 {
+ txreq -req CONNECT -scheme http -url / -hdr ":authority" "a" -hdr ":protocol" "foo" -nostrend
+ rxrst
+ expect rst.err == PROTOCOL_ERROR
+ } -run
+} -run
+
#
# Responses
#