]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: hlua: reject interim responses in HTTP applets
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 19 Nov 2026 15:44:09 +0000 (16:44 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 19 Nov 2026 15:58:22 +0000 (16:58 +0100)
A Lua HTTP service may set a 1xx status. But it can only send one
response, so once the service returns, the interim response is ended
with the EOM flag, which the H1 and H2 muxes never do on a 1xx. The
stream forwards it as an interim response and, the applet being done,
produces a 502 while the interim response is still in the buffer. Since
commit 5fb43f017 ("MEDIUM: htx: Harden HTX API to avoid invalid uses
when EOM was reached") in 3.5-dev8, it crashes on
BUG_ON(htx_msg_ended(dst)). Before, the client got the interim response
followed by the 502.

Let's make start_response() raise a Lua error for interim responses
other than 101, so the service fails with a 500 as for any other error.
The documentation of set_status() was updated accordingly.

No backport needed.

doc/lua-api/index.rst
src/hlua.c

index ffe638429a34c39581440ff3db98c1ca05de8e0a..1bd9be23c4e791b7dc4c3dbb2546a28f898ee2eb 100644 (file)
@@ -3842,7 +3842,8 @@ AppletHTTP class
 .. js:function:: AppletHTTP.set_status(applet, code [, reason])
 
   This function sets the HTTP status code for the response. The allowed code are
-  from 100 to 599.
+  from 100 to 599. Interim responses (1xx except 101) are rejected by
+  *AppletHTTP:start_response()* since no final response could follow.
 
   :param class_AppletHTTP applet: An :ref:`applethttp_class`
   :param integer code: the status code returned to the client.
index 1f227d3543a24d69602c107b4d348914081e5508..18471cb7538e305543901c7c492815c76eba26d1 100644 (file)
@@ -6210,6 +6210,13 @@ __LJMP static int hlua_applet_http_send_response(lua_State *L)
        htx = htx_from_buf(outbuf);
        h1m_init_res(&h1m);
 
+       /* no final response can follow an interim one */
+       if (http_ctx->status < 200 && http_ctx->status != 101) {
+               hlua_pusherror(L, "Lua applet http '%s': interim responses are not supported.\n",
+                              luactx->appctx->applet->name);
+               WILL_LJMP(lua_error(L));
+       }
+
        /* Use the same http version than the request. */
        status = ultoa_r(http_ctx->status, trash.area, trash.size);
        reason = http_ctx->reason;