From: Willy Tarreau Date: Wed, 25 Nov 2026 18:07:51 +0000 (+0000) Subject: REGTESTS: http-messaging: test reject-unexpected-request-payload X-Git-Tag: v3.5-dev14~5 X-Git-Url: https://git.kaiwu.me/http/ngx_http_ssi_module.html?a=commitdiff_plain;h=c43479aa0fcdae7b16108a2e5525bd5396cb5571;p=haproxy.git REGTESTS: http-messaging: test reject-unexpected-request-payload 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. --- diff --git a/reg-tests/http-messaging/http_hardening_h1.vtc b/reg-tests/http-messaging/http_hardening_h1.vtc index d1486fdb6..90a550884 100644 --- a/reg-tests/http-messaging/http_hardening_h1.vtc +++ b/reg-tests/http-messaging/http_hardening_h1.vtc @@ -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 # diff --git a/reg-tests/http-messaging/http_hardening_h2.vtc b/reg-tests/http-messaging/http_hardening_h2.vtc index 9bce6cb9f..e11129a51 100644 --- a/reg-tests/http-messaging/http_hardening_h2.vtc +++ b/reg-tests/http-messaging/http_hardening_h2.vtc @@ -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 #