From: Willy Tarreau Date: Wed, 25 Nov 2026 16:30:26 +0000 (+0100) Subject: MINOR: http/hardening: implement "reject-unexpected-request-payload" X-Git-Tag: v3.5-dev14~6 X-Git-Url: https://git.kaiwu.me/http/%22../hash.html?a=commitdiff_plain;h=de273dafd7d0f63e209ec9aa927658c49630be3c;p=haproxy.git MINOR: http/hardening: implement "reject-unexpected-request-payload" Rejects requests which contain a payload on methods which have no defined semantics with it (HEAD, GET, DELETE, OPTIONS, CONNECT, TRACE), as well as any HTTP/1.1 request using the chunked Transfer-Encoding. This protects backend servers having imperfect implementation against a wide list of attacks that try to abuse their limited parsing to bypass their inspection or desynchronize them with haproxy. The vast majority of applications aimed at browsers will not experience any issue with this setting, but some in-house or proprietary components might rely on passing a payload to some of these methods, or uploading streamed data using Transfer-Encoding. Note that other methods are assumed to support payloads, and unknown methods might be handled similarly to GET by some servers. As such, when using this to protect an application, it is wise to also use 'reject-advanced-methods'. This is generally safe for static web serving and simple internet-facing applications. It is disabled by default. http_hardening_report.vtc was updated accordingly since the new flag appears (0x20000). --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 4260c3ee0..7ac9e818e 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -35060,6 +35060,7 @@ http-hardening [from ] reject-duplicate-content-length on reject-forbidden-payload on reject-advanced-methods off + reject-unexpected-request-payload off It is possible to change their settings from the defaults, by declaring the profiles once, along with the settings to change, in which case they will @@ -35331,6 +35332,23 @@ http-hardening [from ] so it is safe to enable on untrusted listeners. See also the "delete-underscore-in-trailer-name" variant. + - reject-unexpected-request-payload (inbound, request) + Rejects requests which contain a payload on methods which have no + defined semantics with it (HEAD, GET, DELETE, OPTIONS, CONNECT, TRACE), + as well as any HTTP/1.1 request using the chunked Transfer-Encoding. + This protects backend servers having imperfect implementation against a + wide list of attacks that try to abuse their limited parsing to bypass + their inspection or desynchronize them with haproxy. The vast majority + of applications aimed at browsers will not experience any issue with + this setting, but some in-house or proprietary components might rely on + passing a payload to some of these methods, or uploading streamed data + using Transfer-Encoding. Note that other methods are assumed to support + payloads, and unknown methods might be handled similarly to GET by some + servers. As such, when using this to protect an application, it is wise + to also use 'reject-advanced-methods'. This is generally safe for + static web serving and simple internet-facing applications. It is + disabled by default. + /* * Local variables: diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h index dda636659..28195ad48 100644 --- a/include/haproxy/http-t.h +++ b/include/haproxy/http-t.h @@ -260,6 +260,7 @@ struct http_violation { #define HTTP_HRD_REJ_FORB_PAYLOAD 0x00004000 #define HTTP_HRD_REJ_OOR_STATUS 0x00008000 #define HTTP_HRD_REJ_ADV_METH 0x00010000 +#define HTTP_HRD_REJ_UNEXP_REQ_PLD 0x00020000 /* insert new masks above this line */ /* update this one with new rejects */ @@ -274,7 +275,8 @@ struct http_violation { HTTP_HRD_REJ_CL_DUP | \ HTTP_HRD_REJ_FORB_PAYLOAD | \ HTTP_HRD_REJ_OOR_STATUS | \ - HTTP_HRD_REJ_ADV_METH) + HTTP_HRD_REJ_ADV_METH | \ + HTTP_HRD_REJ_UNEXP_REQ_PLD) #define HTTP_HRD_ALL_DELETE (HTTP_HRD_DEL_USCORE_HDR_NAM | \ HTTP_HRD_DEL_USCORE_TLR_NAM | \ diff --git a/reg-tests/http-messaging/http_hardening_report.vtc b/reg-tests/http-messaging/http_hardening_report.vtc index eadfa0ac4..6fcfde37c 100644 --- a/reg-tests/http-messaging/http_hardening_report.vtc +++ b/reg-tests/http-messaging/http_hardening_report.vtc @@ -22,6 +22,7 @@ feature ignore_unknown_macro # 0x040 delete-unregistered-header-fields (only looked up when enabled) # 0x100 delete-all-trailer-fields (any trailer) # 0x400 reject-ctl-in-header-trailer +# 0x20000 reject-unexpected-request-payload (the chunked requests) # The masks are logged in hex after htonl. The H2 frontend has no # backend, so "bs" is not available there. @@ -40,12 +41,12 @@ server s_strict { syslog Strusted -level info { recv - expect ~ "fe_trusted .* fs=00000514/00000000/- bs=00000514/00000000/-$" + expect ~ "fe_trusted .* fs=00020514/00000000/- bs=00000514/00000000/-$" } -start syslog Sreq -level info { recv - expect ~ "fe_req .* fs=00000454/00000450/reject-ctl-in-header-trailer bs=-/-/-$" + expect ~ "fe_req .* fs=00020454/00000450/reject-ctl-in-header-trailer bs=-/-/-$" } -start syslog Sres -level info { diff --git a/src/h1_htx.c b/src/h1_htx.c index ce691ae72..6720d7cf4 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -226,6 +226,19 @@ static int h1_postparse_req_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx goto error; } + /* reject-unexpected-request-payload: reject payload on methods which + * don't have defined semantics for this, as well as chunked encoding + * in requests for any method. + */ + if (((h1m->flags & H1_MF_CHNK) || + ((h1sl->rq.meth == HTTP_METH_GET || h1sl->rq.meth == HTTP_METH_HEAD || h1sl->rq.meth == HTTP_METH_DELETE || + h1sl->rq.meth == HTTP_METH_OPTIONS || h1sl->rq.meth == HTTP_METH_CONNECT || h1sl->rq.meth == HTTP_METH_TRACE) && + (h1m->flags & H1_MF_CLEN) && h1m->body_len != 0)) && + http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD)) { + h1m->err_code = 400; + goto error; + } + /* Remove Upgrade header if no 'connection: upgrade' found */ if ((h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_HDR)) == H1_MF_UPG_HDR) { int i; diff --git a/src/h2.c b/src/h2.c index 0311a8f38..b1c874b3d 100644 --- a/src/h2.c +++ b/src/h2.c @@ -293,6 +293,15 @@ static struct htx_sl *h2_prepare_htx_reqline(uint32_t fields, struct ist *phdr, http_harden(HTTP_HRD_REJ_ADV_METH)) goto fail; + /* reject-unexpected-request-payload: reject payload on methods which + * don't have defined semantics for this. + */ + if ((*msgf & H2_MSGF_BODY) && + (meth == HTTP_METH_GET || meth == HTTP_METH_HEAD || meth == HTTP_METH_DELETE || + meth == HTTP_METH_OPTIONS || meth == HTTP_METH_CONNECT || meth == HTTP_METH_TRACE) && + http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD)) + goto fail; + sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth_sl, uri, ist("HTTP/2.0")); if (!sl) goto fail; diff --git a/src/h3.c b/src/h3.c index 705a9d58f..e395c7ff7 100644 --- a/src/h3.c +++ b/src/h3.c @@ -1072,6 +1072,21 @@ static ssize_t h3_req_headers_to_htx(struct qcs *qcs, const struct buffer *buf, goto out; } + /* reject-unexpected-request-payload: reject payload on methods which + * don't have defined semantics for this. + */ + if (!fin && + (sl->info.req.meth == HTTP_METH_GET || sl->info.req.meth == HTTP_METH_HEAD || + sl->info.req.meth == HTTP_METH_DELETE || sl->info.req.meth == HTTP_METH_OPTIONS || + sl->info.req.meth == HTTP_METH_CONNECT || sl->info.req.meth == HTTP_METH_TRACE) && + http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD)) { + TRACE_ERROR("hardening rejected unexpected payload for method", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs); + h3s->err = H3_ERR_REQUEST_REJECTED; + qcc_report_glitch(h3c->qcc, 1); + len = -1; + goto out; + } + if (isttest(authority)) { if (!htx_add_header(htx, ist("host"), authority)) { len = -1; diff --git a/src/http.c b/src/http.c index fed3cc58a..a96cbdd74 100644 --- a/src/http.c +++ b/src/http.c @@ -1805,6 +1805,7 @@ const struct http_hardening_kw http_hardening_kws[] = { { "reject-forbidden-payload", HTTP_HRD_REJ_FORB_PAYLOAD, HTTP_DIR_RES }, { "reject-out-of-range-status", HTTP_HRD_REJ_OOR_STATUS, HTTP_DIR_RES }, { "reject-advanced-methods", HTTP_HRD_REJ_ADV_METH, HTTP_DIR_REQ }, + { "reject-unexpected-request-payload", HTTP_HRD_REJ_UNEXP_REQ_PLD, HTTP_DIR_REQ }, /* insert new hardening options above this line */ { "all-reject", HTTP_HRD_ALL_REJECT, HTTP_DIR_BOTH }, { "all-delete", HTTP_HRD_ALL_DELETE, HTTP_DIR_BOTH },