diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 78705bdef..3f127c78e 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -3347,6 +3347,20 @@ static size_t fcgi_strm_parse_headers(struct fcgi_strm *fstrm, struct h1m *h1m, goto end; } + /* Reject any message with an unknown transfer-encoding. In fact if any + * encoding other than "chunked". A 422-Unprocessable-Content is + * returned for an invalid request, a 502-Bad-Gateway for an invalid + * response. + */ + if (h1m->flags & H1_MF_TE_OTHER) { + htx->flags |= HTX_FL_PARSING_ERROR; + TRACE_ERROR("Unknown transfer-encoding", FCGI_EV_RSP_DATA|FCGI_EV_RSP_HDRS|FCGI_EV_FSTRM_ERR, fstrm->fconn->conn, fstrm); + fcgi_strm_error(fstrm); + fcgi_strm_capture_bad_message(fstrm->fconn, fstrm, h1m, buf); + ret = 0; + goto end; + } + *ofs += ret; end: TRACE_LEAVE(FCGI_EV_RSP_DATA|FCGI_EV_RSP_HDRS, fstrm->fconn->conn, fstrm, 0, (size_t[]){ret}); diff --git a/src/mux_h1.c b/src/mux_h1.c index 47322cb3e..dcfa3eef0 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1420,6 +1420,22 @@ static size_t h1_handle_headers(struct h1s *h1s, struct h1m *h1m, struct htx *ht goto end; } + /* Reject any message with an unknown transfer-encoding. In fact if any + * encoding other than "chunked". A 422-Unprocessable-Content is + * returned for an invalid request, a 502-Bad-Gateway for an invalid + * response. + */ + if (h1m->flags & H1_MF_TE_OTHER) { + h1s->flags |= H1S_F_PARSING_ERROR; + htx->flags |= HTX_FL_PARSING_ERROR; + if (!(h1m->flags & H1_MF_RESP)) + h1s->h1c->errcode = 422; + TRACE_ERROR("Unknown transfer-encoding", H1_EV_RX_DATA|H1_EV_RX_HDRS|H1_EV_H1S_ERR, h1s->h1c->conn, h1s); + h1_capture_bad_message(h1s->h1c, h1s, h1m, buf); + ret = 0; + goto end; + } + /* If websocket handshake, search for the websocket key */ if ((h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) == (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) {