]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: http-messaging: test reject-unexpected-request-payload
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-unexpected-request-payload" check to the HTTP/1
and H2 tests, in its own profile on its own bind line, and a GET with a
body and a chunked POST to the reference connection which has everything
off. A payload is accepted with POST, PUT and PATCH, an empty one with
GET, but a non-empty one gets a 400 or STREAM_ERROR with GET, HEAD,
DELETE, OPTIONS and TRACE, as does any chunked request.

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

index d1486fdb6d5362a66b52f6c9de66fd45129f5a49..90a5508841b7deb0a974151a081f78a32f3fce45 100644 (file)
@@ -153,6 +153,9 @@ haproxy h1 -conf {
     http-hardening adv-meth
        reject-advanced-methods on
 
+    http-hardening req-pld
+       reject-unexpected-request-payload on
+
     defaults
        mode http
        http-reuse never
@@ -174,6 +177,7 @@ haproxy h1 -conf {
        bind "fd@${req_clte}"     http-hardening clte
        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]"
 
     # response side: one listener per server profile
@@ -264,6 +268,14 @@ client c_req_off -connect ${h1_req_off_sock} {
        expect resp.status == 200
        expect resp.http.x-meth == "MY-METH"
 
+       txreq -nouseragent -req GET -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req POST -nolen -hdr "transfer-encoding: chunked" -body "2\r\nok\r\n0\r\n\r\n"
+       rxresp
+       expect resp.status == 200
+
        # 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
@@ -521,6 +533,78 @@ client c_req_adv_meth5 -connect ${h1_req_adv_meth_sock} {
        expect_close
 } -run
 
+# payloads are accepted on methods which define their semantics, and an
+# empty one is accepted everywhere. Chunking is always rejected.
+client c_req_pld -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req GET
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req GET -nolen -hdr "content-length: 0"
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req POST -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req PUT -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req PATCH -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 200
+
+       txreq -nouseragent -req GET -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
+# the error response to HEAD carries a body that vtest doesn't read, so there
+# is no expect_close here.
+client c_req_pld2 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req HEAD -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 400
+} -run
+
+client c_req_pld3 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req DELETE -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
+client c_req_pld4 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req OPTIONS -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
+client c_req_pld5 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req TRACE -nolen -hdr "content-length: 2" -body "ok"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
+client c_req_pld6 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req POST -nolen -hdr "transfer-encoding: chunked" -body "2\r\nok\r\n0\r\n\r\n"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
+client c_req_pld7 -connect ${h1_req_pld_sock} {
+       txreq -nouseragent -req GET -nolen -hdr "transfer-encoding: chunked" -body "0\r\n\r\n"
+       rxresp
+       expect resp.status == 400
+       expect_close
+} -run
+
 #
 # Responses
 #
index 9bce6cb9f4d39031defce7e9b227d8fa9716d5a6..e11129a51bd778fa492c623ad904d92a468783ea 100644 (file)
@@ -263,6 +263,9 @@ haproxy h1 -conf {
     http-hardening adv-meth
        reject-advanced-methods on
 
+    http-hardening req-pld
+       reject-unexpected-request-payload on
+
     defaults
        mode http
        http-reuse never
@@ -282,6 +285,7 @@ haproxy h1 -conf {
        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
+       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]"
 
     # response side: one listener per server
@@ -409,6 +413,11 @@ client c_req_off -connect ${h1_req_off_sock} {
                expect resp.status == 200
                expect resp.http.x-meth == "MY-METH"
        } -run
+       stream 17 {
+               txreq -req GET -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxresp
+               expect resp.status == 200
+       } -run
 } -run
 
 # without :authority, Host is the only source of the authority
@@ -692,6 +701,64 @@ client c_req_adv_meth -connect ${h1_req_adv_meth_sock} {
        } -run
 } -run
 
+# payloads are only accepted on methods which define their semantics
+client c_req_pld -connect ${h1_req_pld_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
+       } -run
+       stream 3 {
+               txreq -req POST -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxresp
+               expect resp.status == 200
+       } -run
+       stream 5 {
+               txreq -req PUT -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxresp
+               expect resp.status == 200
+       } -run
+       stream 7 {
+               txreq -req PATCH -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxresp
+               expect resp.status == 200
+       } -run
+       stream 9 {
+               txreq -req GET -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxrst
+               expect rst.err == PROTOCOL_ERROR
+       } -run
+       stream 11 {
+               txreq -req HEAD -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxrst
+               expect rst.err == PROTOCOL_ERROR
+       } -run
+       stream 13 {
+               txreq -req DELETE -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxrst
+               expect rst.err == PROTOCOL_ERROR
+       } -run
+       stream 15 {
+               txreq -req OPTIONS -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxrst
+               expect rst.err == PROTOCOL_ERROR
+       } -run
+       stream 17 {
+               txreq -req TRACE -url / -scheme http -hdr ":authority" "a" -body "ok"
+               rxrst
+               expect rst.err == PROTOCOL_ERROR
+       } -run
+} -run
+
 #
 # Responses
 #