]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: h1: reject a short status code without reason phrase
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 14:32:39 +0000 (15:32 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 4 Dec 2026 13:53:05 +0000 (14:53 +0100)
Since the commit 8a47f9028 ("MEDIUM: http: add the "short-status-code"
violation exception"), status codes shorter than 3 digits are rejected by
default. But the check was only performed when the status code was
followed by a space. When it was directly followed by the end of line,
without reason phrase, the status code was still accepted. For
instance, "HTTP/1.1 20\r\n" was accepted while "HTTP/1.1 20 OK\r\n" was
rejected.

Now the status code length is checked in both cases.

This patch must be backported to 3.5, and with the commit above if it is
backported further.

src/h1.c

index 563a1b77307ca9254b4eef20a952fd4aab433df0..cce2c358070c1ab7f1e753cdcc59f959e3677135 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -778,23 +778,22 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                        goto http_msg_invalid;
                }
 
-               if (likely(HTTP_IS_SPHT(*ptr))) {
-                       sl.st.c.len = ptr - sl.st.c.ptr;
-                       if (sl.st.c.len < 3) {
-                               /* less than 3 digits */
-                               if (h1m->err_pos < -1 || !(global.acc_hres_vio & (1U << HTTP_VIO_STATUS_SHORT))) {
-                                       state = H1_MSG_RPCODE;
-                                       goto http_msg_invalid;
-                               } else if (h1m->err_pos == -1) {
-                                       /* only capture the error pointer */
-                                       h1m->err_pos = ptr - start + skip;
-                               }
+               sl.st.c.len = ptr - sl.st.c.ptr;
+               if (sl.st.c.len < 3) {
+                       /* less than 3 digits */
+                       if (h1m->err_pos < -1 || !(global.acc_hres_vio & (1U << HTTP_VIO_STATUS_SHORT))) {
+                               state = H1_MSG_RPCODE;
+                               goto http_msg_invalid;
+                       } else if (h1m->err_pos == -1) {
+                               /* only capture the error pointer */
+                               h1m->err_pos = ptr - start + skip;
                        }
-                       EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP);
                }
 
+               if (likely(HTTP_IS_SPHT(*ptr)))
+                       EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_rpcode_sp, http_msg_ood, state, H1_MSG_RPCODE_SP);
+
                /* so it's a CR/LF, so there is no reason phrase */
-               sl.st.c.len = ptr - sl.st.c.ptr;
 
        http_msg_rsp_reason:
                sl.st.r = ist2(ptr, 0);