Skip to content

Commit 2901d0c

Browse files
committed
BUG/MAJOR: h3: check body size with content-length on empty FIN
In QUIC, a STREAM frame may be received with no data but with FIN bit set. Parsing code in haproxy has changed several times to deal with it. Now, in most of h3_rcv_buf() parsing code is skipped and the common function qcs_http_handle_standalone_fin() is used to deal with it at the HTX level. However, this bypass an important HTTP/3 validation check on the received body size if a content-length header was present. Under some conditions, this could cause a desynchronization with the backend server which could be exploited for request smuggling. Fix this by using h3_check_body_size() if content-length is present when dealing with a standalone FIN in h3_rcv_buf(). If the received body size is incorrect, the stream is immediately resetted with H3_MESSAGE_ERROR code and the error is forwarded to the stream layer. Thanks to Martino Spagnuolo for his detailed report on this issue and for having contacting us about it via the security mailing list. This must be backported up to 2.6.
1 parent 29592cb commit 2901d0c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/h3.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,14 @@ static ssize_t h3_rcv_buf(struct qcs *qcs, struct buffer *b, int fin)
17541754

17551755
if (!b_data(b) && fin && quic_stream_is_bidi(qcs->id)) {
17561756
TRACE_PROTO("received FIN without data", H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
1757+
1758+
/* FIN received, ensure body length is conform to any content-length header. */
1759+
if ((h3s->flags & H3_SF_HAVE_CLEN) && h3_check_body_size(qcs, 1)) {
1760+
qcc_abort_stream_read(qcs);
1761+
qcc_reset_stream(qcs, h3s->err);
1762+
goto done;
1763+
}
1764+
17571765
if (qcs_http_handle_standalone_fin(qcs)) {
17581766
TRACE_ERROR("cannot set EOM", H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
17591767
qcc_set_error(qcs->qcc, H3_ERR_INTERNAL_ERROR, 1);

0 commit comments

Comments
 (0)