]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: http-messaging: test reject-advanced-methods
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 18:07:51 +0000 (18:07 +0000)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 18:31:08 +0000 (19:31 +0100)
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.

reg-tests/http-messaging/http_hardening_h1.vtc
reg-tests/http-messaging/http_hardening_h2.vtc

index 41a3c4cd38e2077b0ef7abf3cbc841a0416a491d..d1486fdb6d5362a66b52f6c9de66fd45129f5a49 100644 (file)
@@ -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
 #
index b7a72f4f450b44753918d2ce75dc53532192e50e..9bce6cb9f4d39031defce7e9b227d8fa9716d5a6 100644 (file)
@@ -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
 #