]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: http_ana: control acceptance of 1xx status on HTTP/1.0
authorWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 07:53:30 +0000 (08:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 23 Nov 2026 22:24:23 +0000 (23:24 +0100)
HTTP/1.0 doesn't define status codes 1xx and these ones are not uniformly
handled across agents. These must never be emitted, neither by an 1.0
server nor to an 1.0 client, or there is a risk of smuggling. Let's
block them by default, and subject them to the "http-1.0-status-1xx"
response violation rule.

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

index 0fd15bbe6a36b0152eefea578708d058a5a18858..408525b8b7636e34b06932dbc417506ef105eff7 100644 (file)
@@ -2291,6 +2291,13 @@ acceptable-http-response-violations { [-+]<http-violation>[,...] }
       should only be used between trusted WebSocket endpoints, and the risk is
       moderate.
 
+    - "http-1.0-status-1xx" (response): this controls the acceptance of HTTP
+      status codes below 200 in responses from or to HTTP/1.0 messages. These
+      ranges were specified as reserved and are not uniformly implemented
+      across implementations, and present a risk of smuggling. This should only
+      be used with confirmed valid endpoints, and the risk is low because
+      HTTP/1.0-only agents became rare.
+
   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 96946c78fd1517adadadbc94e1f6809e70115c73..15f7d41861606e312eea9571e9cdb1a9ea1a02bb 100644 (file)
@@ -223,6 +223,7 @@ enum http_violation_idx {
        HTTP_VIO_AUTH_HOST_DIFF,   // authority and host field mismatch
        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
        /* insert new violations above this line */
        HTTP_VIO_TOTAL_COUNT = 32, // end marker
        HTTP_VIO_NONE,             // special code for none
index bd9e96315028c0478a212727802bdfd4315543b0..b07851ff8633364eae189560122af02ce7f36e7f 100644 (file)
@@ -1666,6 +1666,7 @@ const struct http_violation http_violations[] = {
        { "mismatch-authority-host",        HTTP_VIO_AUTH_HOST_DIFF,   HTTP_DIR_REQ  },
        { "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  },
        /* insert new violations above this line */
        { "all",                            HTTP_VIO_ALL,              HTTP_DIR_BOTH },
        { NULL, 0 }
index 0eb4721b6409af6c42cf31aedfee642e502b85e1..fb87d5ec48abc9e3446ff24ffbe04998797691bd 100644 (file)
@@ -1602,29 +1602,41 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
         * response, and we're waiting for the next one. Let's allow this response
         * to go to the client and wait for the next one. There's an exception for
         * 101 which is used later in the code to switch protocols.
+        *
+        * Anyway, for HTTP/1.0 (client or server), <200 is forbidden.
         */
-       if (txn->status < 200 &&
-           (txn->status == 100 || txn->status >= 102)) {
-               FLT_STRM_CB(s, flt_http_reset(s, msg));
-               htx->first = channel_htx_fwd_headers(rep, htx);
-               msg->msg_state = HTTP_MSG_RPBEFORE;
-               msg->flags = 0;
-               txn->server_status = txn->status = 0;
-               s->logs.t_data = -1; /* was not a response yet */
-               s->scf->flags |= SC_FL_SND_ASAP; /* Send ASAP informational messages */
-               goto next_one;
-       }
-
-       /* A 101-switching-protocols must contains a Connection header with the
-        * "upgrade" option and the request too. It means both are agree to
-        * upgrade. It is not so strict because there is no test on the Upgrade
-        * header content. But it is probably stronger enough for now.
-        */
-       if (txn->status == 101 &&
-           (!(txn->req.flags & HTTP_MSGF_CONN_UPG) || !(txn->rsp.flags & HTTP_MSGF_CONN_UPG))) {
-               if (objt_server(s->target))
-                       health_adjust(__objt_server(s->target), HANA_STATUS_HTTP_HDRRSP);
-               goto return_bad_res;
+       if (unlikely(txn->status < 200)) {
+               if (!(txn->req.flags & txn->rsp.flags & HTTP_MSGF_VER_11) &&
+                   !(s->be->options2 & PR_O2_RSPBUG_OK &&
+                     global.acc_hres_vio & (1U << HTTP_VIO_1XX_HTTP_1_0))) {
+                       /* at least one side is not 1.1 compatible, this is a violation */
+                       if (objt_server(s->target))
+                               health_adjust(__objt_server(s->target), HANA_STATUS_HTTP_HDRRSP);
+                       goto return_bad_res;
+               }
+
+               if (txn->status == 100 || txn->status >= 102) {
+                       FLT_STRM_CB(s, flt_http_reset(s, msg));
+                       htx->first = channel_htx_fwd_headers(rep, htx);
+                       msg->msg_state = HTTP_MSG_RPBEFORE;
+                       msg->flags = 0;
+                       txn->server_status = txn->status = 0;
+                       s->logs.t_data = -1; /* was not a response yet */
+                       s->scf->flags |= SC_FL_SND_ASAP; /* Send ASAP informational messages */
+                       goto next_one;
+               }
+
+               /* A 101-switching-protocols must contains a Connection header with the
+                * "upgrade" option and the request too. It means both are agree to
+                * upgrade. It is not so strict because there is no test on the Upgrade
+                * header content. But it is probably stronger enough for now.
+                */
+               if (txn->status == 101 &&
+                   (!(txn->req.flags & HTTP_MSGF_CONN_UPG) || !(txn->rsp.flags & HTTP_MSGF_CONN_UPG))) {
+                       if (objt_server(s->target))
+                               health_adjust(__objt_server(s->target), HANA_STATUS_HTTP_HDRRSP);
+                       goto return_bad_res;
+               }
        }
 
        /*