From: Willy Tarreau Date: Wed, 25 Nov 2026 18:07:51 +0000 (+0000) Subject: REGTESTS: http-messaging: test reject-advanced-methods X-Git-Url: https://git.kaiwu.me/web//%22%22?a=commitdiff_plain;h=bef12a40c2b4d77e0736ddae44778f7605bb2b84;p=haproxy.git REGTESTS: http-messaging: test reject-advanced-methods This adds the "reject-advanced-methods" check to the HTTP/1 and H2 test, in its own profile on its own bind line, and TRACE and an unknown method to the reference connection which has everything off. Only GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH and QUERY are accepted, while TRACE, CONNECT (there is no extended CONNECT in HTTP/1), unknown methods and methods differing from PATCH or QUERY by their length get a 405 or a stream error. --- diff --git a/reg-tests/http-messaging/http_hardening_h1.vtc b/reg-tests/http-messaging/http_hardening_h1.vtc index 41a3c4cd3..d1486fdb6 100644 --- a/reg-tests/http-messaging/http_hardening_h1.vtc +++ b/reg-tests/http-messaging/http_hardening_h1.vtc @@ -150,6 +150,9 @@ haproxy h1 -conf { http-hardening cl0 reject-content-length-leading-zero on + http-hardening adv-meth + reject-advanced-methods on + defaults mode http http-reuse never @@ -170,6 +173,7 @@ haproxy h1 -conf { bind "fd@${req_ctl}" http-hardening ctl bind "fd@${req_clte}" http-hardening clte bind "fd@${req_cl0}" http-hardening cl0 + bind "fd@${req_adv_meth}" http-hardening adv-meth http-request return status 200 hdr x-meth "%[method]" hdr x-hdrs "%[req.hdr_names]" hdr x-foo "%[req.hdr(foo),hex]" # response side: one listener per server profile @@ -250,6 +254,16 @@ client c_req_off -connect ${h1_req_off_sock} { rxresp expect resp.status == 200 + txreq -nouseragent -req TRACE + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "TRACE" + + txreq -nouseragent -req MY-METH + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "MY-METH" + # 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 @@ -435,6 +449,78 @@ client c_req_cl02 -connect ${h1_req_cl0_sock} { expect_close } -run +# only the most common methods are accepted. CONNECT is always rejected since +# there is no extended CONNECT in HTTP/1. +client c_req_adv_meth -connect ${h1_req_adv_meth_sock} { + txreq -nouseragent -req GET + rxresp + expect resp.status == 200 + + txreq -nouseragent -req HEAD + rxresp -no_obj + expect resp.status == 200 + + txreq -nouseragent -req POST + rxresp + expect resp.status == 200 + + txreq -nouseragent -req PUT + rxresp + expect resp.status == 200 + + txreq -nouseragent -req DELETE + rxresp + expect resp.status == 200 + + txreq -nouseragent -req OPTIONS + rxresp + expect resp.status == 200 + + txreq -nouseragent -req PATCH + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "PATCH" + + txreq -nouseragent -req QUERY + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "QUERY" + + txreq -nouseragent -req TRACE + rxresp + expect resp.status == 405 + expect_close +} -run + +client c_req_adv_meth2 -connect ${h1_req_adv_meth_sock} { + txreq -nouseragent -req CONNECT -url "a:443" -nohost -hdr "host: a:443" + rxresp + expect resp.status == 405 + expect_close +} -run + +client c_req_adv_meth3 -connect ${h1_req_adv_meth_sock} { + txreq -nouseragent -req MY-METH + rxresp + expect resp.status == 405 + expect_close +} -run + +# methods which may only differ from the accepted ones by their length +client c_req_adv_meth4 -connect ${h1_req_adv_meth_sock} { + txreq -nouseragent -req PATCHX + rxresp + expect resp.status == 405 + expect_close +} -run + +client c_req_adv_meth5 -connect ${h1_req_adv_meth_sock} { + txreq -nouseragent -req QUER + rxresp + expect resp.status == 405 + expect_close +} -run + # # Responses # diff --git a/reg-tests/http-messaging/http_hardening_h2.vtc b/reg-tests/http-messaging/http_hardening_h2.vtc index b7a72f4f4..9bce6cb9f 100644 --- a/reg-tests/http-messaging/http_hardening_h2.vtc +++ b/reg-tests/http-messaging/http_hardening_h2.vtc @@ -260,6 +260,9 @@ haproxy h1 -conf { http-hardening cl0 reject-content-length-leading-zero on + http-hardening adv-meth + reject-advanced-methods on + defaults mode http http-reuse never @@ -278,6 +281,7 @@ haproxy h1 -conf { bind "fd@${req_unreg}" proto h2 http-hardening unreg bind "fd@${req_ctl}" proto h2 http-hardening ctl bind "fd@${req_cl0}" proto h2 http-hardening cl0 + bind "fd@${req_adv_meth}" proto h2 http-hardening adv-meth http-request return status 200 hdr x-meth "%[method]" hdr x-hdrs "%[req.hdr_names]" hdr x-foo "%[req.hdr(foo),hex]" # response side: one listener per server @@ -393,6 +397,18 @@ client c_req_off -connect ${h1_req_off_sock} { rxresp expect resp.status == 200 } -run + stream 13 { + txreq -req TRACE -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "TRACE" + } -run + stream 15 { + txreq -req MY-METH -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "MY-METH" + } -run } -run # without :authority, Host is the only source of the authority @@ -601,6 +617,81 @@ client c_req_cl0 -connect ${h1_req_cl0_sock} { } -run } -run +# only the most common methods are accepted +client c_req_adv_meth -connect ${h1_req_adv_meth_sock} { + txpri + stream 0 { + txsettings + rxsettings + txsettings -ack + rxsettings + expect settings.ack == true + } -run + + stream 1 { + txreq -req GET -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "GET" + } -run + stream 3 { + txreq -req POST -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "POST" + } -run + stream 5 { + txreq -req PUT -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "PUT" + } -run + stream 7 { + txreq -req DELETE -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "DELETE" + } -run + stream 9 { + txreq -req OPTIONS -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "OPTIONS" + } -run + stream 11 { + txreq -req PATCH -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "PATCH" + } -run + stream 13 { + txreq -req QUERY -url / -scheme http -hdr ":authority" "a" + rxresp + expect resp.status == 200 + expect resp.http.x-meth == "QUERY" + } -run + stream 15 { + txreq -req TRACE -url / -scheme http -hdr ":authority" "a" + rxrst + expect rst.err == PROTOCOL_ERROR + } -run + stream 17 { + txreq -req MY-METH -url / -scheme http -hdr ":authority" "a" + rxrst + expect rst.err == PROTOCOL_ERROR + } -run + stream 19 { + txreq -req PATCHX -url / -scheme http -hdr ":authority" "a" + rxrst + expect rst.err == PROTOCOL_ERROR + } -run + stream 21 { + txreq -req QUER -url / -scheme http -hdr ":authority" "a" + rxrst + expect rst.err == PROTOCOL_ERROR + } -run +} -run + # # Responses #