]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http/hardening: implement "reject-unexpected-request-payload"
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 16:30:26 +0000 (17:30 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 18:31:08 +0000 (19:31 +0100)
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).

doc/configuration.txt
include/haproxy/http-t.h
reg-tests/http-messaging/http_hardening_report.vtc
src/h1_htx.c
src/h2.c
src/h3.c
src/http.c

index 4260c3ee00a3a07e0866b601b2e346678a1f107a..7ac9e818ea1134b8bbce8833431bb577b9336c38 100644 (file)
@@ -35060,6 +35060,7 @@ http-hardening <name> [from <source>]
         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 <name> [from <source>]
         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:
index dda636659eb69d039bf7678654e923d7247be438..28195ad4880c8164a9c0a650e716970d38b2f115 100644 (file)
@@ -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         | \
index eadfa0ac4d9ba46f3e1164ffce4f96432bafe7c3..6fcfde37cf06f8d92c2dc7b12c8aa566a1a46c05 100644 (file)
@@ -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 {
index ce691ae723f6898aa2dab587c9e574ce94ba2d61..6720d7cf458ea1eb14e01c54018f985d7ef2cb09 100644 (file)
@@ -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;
index 0311a8f38b2a50cd0eb1d1e1bcd9efeaa0b6ee16..b1c874b3d16f6bb7ee8a40f5466b67c738c975c2 100644 (file)
--- 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;
index 705a9d58f9df8b53ef871788238007efcee18f01..e395c7ff77a04ec39dedd528cff5d8a3c4cfe0ab 100644 (file)
--- 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;
index fed3cc58a8c9af5143bf3c5cde91e2e7f3d49d58..a96cbdd74901399bf75ae8b55303c1ad36ff156a 100644 (file)
@@ -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 },