]> git.kaiwu.me - nginx.git/commitdiff
HTTP/3: fixed handling of malformed request body length.
authorSergey Kandaurov <pluknet@nginx.com>
Fri, 3 May 2024 16:28:32 +0000 (20:28 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 3 May 2024 16:28:32 +0000 (20:28 +0400)
Previously, a request body larger than declared in Content-Length resulted in
a 413 status code, because Content-Length was mistakenly used as the maximum
allowed request body, similar to client_max_body_size.  Following the HTTP/3
specification, such requests are now rejected with the 400 error as malformed.

src/http/v3/ngx_http_v3_request.c

index 87f5f3214cd09fdc2f72741bc9a817bb91ce2d6d..aec122be612b9568bef93fcd8f8a7632394e5344 100644 (file)
@@ -1575,6 +1575,15 @@ ngx_http_v3_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
                 /* rc == NGX_OK */
 
                 if (max != -1 && (uint64_t) (max - rb->received) < st->length) {
+
+                    if (r->headers_in.content_length_n != -1) {
+                        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                                      "client intended to send body data "
+                                      "larger than declared");
+
+                        return NGX_HTTP_BAD_REQUEST;
+                    }
+
                     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                                   "client intended to send too large "
                                   "body: %O+%ui bytes",