From: Willy Tarreau Date: Mon, 23 Nov 2026 16:53:32 +0000 (+0100) Subject: MINOR: http: add a new violation rule "trace-with-content" for TRACE methods X-Git-Url: https://git.kaiwu.me/http/ngx_http_proxy_module.html?a=commitdiff_plain;h=e2ff0935324be8f4f41d542468e5f05d556fcb06;p=haproxy.git MINOR: http: add a new violation rule "trace-with-content" for TRACE methods 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). --- diff --git a/doc/configuration.txt b/doc/configuration.txt index f33251827..42f695948 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2298,6 +2298,15 @@ acceptable-http-response-violations { [-+][,...] } 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" diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h index 07df4b30b..1fc3fc5dd 100644 --- a/include/haproxy/http-t.h +++ b/include/haproxy/http-t.h @@ -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 diff --git a/src/http.c b/src/http.c index b047b31c4..56b3da6d5 100644 --- a/src/http.c +++ b/src/http.c @@ -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 } diff --git a/src/http_ana.c b/src/http_ana.c index 9d208798a..d0e77c437 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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;