]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http: add a new violation rule "trace-with-content" for TRACE methods
authorWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 16:53:32 +0000 (17:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 22:24:23 +0000 (23:24 +0100)
The TRACE method must not be used with a content according to the latest
specifications, as it can be used to build smuggling attacks depending on
server implementations. This is blocked as a violation, and can be released
via "trace-with-content" if there is a compelling reason (there should not
be any).

doc/configuration.txt
include/haproxy/http-t.h
src/http.c
src/http_ana.c

index f332518277c1fa99b8c3760e3021c8efcc7a52f3..42f6959489cdc7e9cd4672b5de3392115653c168 100644 (file)
@@ -2298,6 +2298,15 @@ acceptable-http-response-violations { [-+]<http-violation>[,...] }
       be used with confirmed valid endpoints, and the risk is low because
       HTTP/1.0-only agents became rare.
 
+    - "trace-with-content" (request): this controls the acceptance of TRACE
+      HTTP requests containing a message body. This is forbidden by latest
+      updates of the specification because it can be used to build smuggling
+      attacks with certain servers. TRACE is exclusively used for attacks and
+      occasionally for debugging anyway. The risk is high, particularly for
+      requests originating from untrusted clients. Do not enable this without
+      verifying that servers support it and that the application absolutely
+      requires it.
+
   By default, for backward compatibility, all violations above are flagged as
   acceptable, meaning that a proxy having "option accept-unsafe-http-*" will
   accept them all. It may be a good practice to explicitly reset them to "none"
index 07df4b30b80c9e959c5a0c9f87829947d85b3397..1fc3fc5ddb1399e747a9b94f2881b3d836f37b33 100644 (file)
@@ -224,6 +224,7 @@ enum http_violation_idx {
        HTTP_VIO_VERSION_STRING,   // unsupported version string
        HTTP_VIO_WEBSOCKET_KEY,    // invalid or missing websocket-key header
        HTTP_VIO_1XX_HTTP_1_0,     // 1xx in response from or to HTTP/1.0
+       HTTP_VIO_TRACE_CONTENT,    // TRACE with C-L>0 or T-E
        /* insert new violations above this line */
        HTTP_VIO_TOTAL_COUNT = 32, // end marker
        HTTP_VIO_NONE,             // special code for none
index b047b31c462afed74347622e2f204cb8e8f3f0bf..56b3da6d5854c87c6964567439850861ae1bb02b 100644 (file)
@@ -1667,6 +1667,7 @@ const struct http_violation http_violations[] = {
        { "invalid-version-string",         HTTP_VIO_VERSION_STRING,   HTTP_DIR_BOTH },
        { "invalid-websocket-key",          HTTP_VIO_WEBSOCKET_KEY,    HTTP_DIR_BOTH },
        { "http-1.0-status-1xx",            HTTP_VIO_1XX_HTTP_1_0,     HTTP_DIR_RES  },
+       { "trace-with-content",             HTTP_VIO_TRACE_CONTENT,    HTTP_DIR_REQ  },
        /* insert new violations above this line */
        { "all",                            HTTP_VIO_ALL,              HTTP_DIR_BOTH },
        { NULL, 0 }
index 9d208798abbd59e2beea97f4ee9ae3bd47882fd0..d0e77c437659e0c3609143c14e7ab868fe1ed7fe 100644 (file)
@@ -205,6 +205,19 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
        if (sl->flags & HTX_SL_F_CONN_UPG)
                msg->flags |= HTTP_MSGF_CONN_UPG;
 
+       /* check for incompatibilities with content */
+       if (!(msg->flags & HTTP_MSGF_BODYLESS)) {
+               /* there IS a body, either via T-E, or C-L > 0. For TRACE, this
+                * is a violation of RFC9110 #9.3.8.
+                */
+               if (txn->meth == HTTP_METH_TRACE &&
+                   !(s->be->options2 & PR_O2_REQBUG_OK &&
+                     global.acc_hreq_vio & (1U << HTTP_VIO_TRACE_CONTENT))) {
+                       stream_inc_http_err_ctr(s);
+                       goto return_bad_req;
+               }
+       }
+
        /* we can make use of server redirect on GET and HEAD */
        if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD)
                s->flags |= SF_REDIRECTABLE;