Welcome! Log In Create A New Profile

Advanced

[PATCH] HTTP/3: fixed handling of malformed request body length

Sergey Kandaurov
April 22, 2024 11:02AM
# HG changeset patch
# User Sergey Kandaurov <pluknet@nginx.com>
# Date 1713798017 -14400
# Mon Apr 22 19:00:17 2024 +0400
# Node ID 754e32eaca24ad751e2a94790e1afd55202c1aba
# Parent 9f84f2e49c624e82e054a2dcd48723119c44029c
HTTP/3: fixed handling of malformed request body length.

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.

diff --git a/src/http/v3/ngx_http_v3_request.c b/src/http/v3/ngx_http_v3_request.c
--- a/src/http/v3/ngx_http_v3_request.c
+++ b/src/http/v3/ngx_http_v3_request.c
@@ -1575,12 +1575,21 @@ ngx_http_v3_request_body_filter(ngx_http
/* rc == NGX_OK */

if (max != -1 && (uint64_t) (max - rb->received) < st->length) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client intended to send too large "
- "body: %O+%ui bytes",
- rb->received, st->length);
+
+ if (max == r->headers_in.content_length_n) {
+ ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+ "client intended to send body data "
+ "larger than declared");
+
+ return NGX_HTTP_BAD_REQUEST;

- return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
+ } else {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "client intended to send too large body: "
+ "%O+%ui bytes", rb->received, st->length);
+
+ return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
+ }
}

continue;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] HTTP/3: fixed handling of malformed request body length

Sergey Kandaurov 293 April 22, 2024 11:02AM

Re: [PATCH] HTTP/3: fixed handling of malformed request body length

Sergey Kandaurov 67 April 23, 2024 09:16AM

Re: [PATCH] HTTP/3: fixed handling of malformed request body length

Roman Arutyunyan 95 April 23, 2024 09:50AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 219
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready