]> git.kaiwu.me - nginx.git/commitdiff
Disabled requests with both Content-Length and Transfer-Encoding.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 28 Jun 2021 15:01:06 +0000 (18:01 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 28 Jun 2021 15:01:06 +0000 (18:01 +0300)
HTTP clients are not allowed to generate such requests since Transfer-Encoding
introduction in RFC 2068, and they are not expected to appear in practice
except in attempts to perform a request smuggling attack.  While handling of
such requests is strictly defined, the most secure approach seems to reject
them.

src/http/ngx_http_request.c

index 5b2613870afbbbf5ff10e285570e8cccd2b10ff0..2614b998c141a31288cba1c1b2f84dd71d60c363 100644 (file)
@@ -1985,8 +1985,15 @@ ngx_http_process_request_header(ngx_http_request_t *r)
             && ngx_strncasecmp(r->headers_in.transfer_encoding->value.data,
                                (u_char *) "chunked", 7) == 0)
         {
-            r->headers_in.content_length = NULL;
-            r->headers_in.content_length_n = -1;
+            if (r->headers_in.content_length) {
+                ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                              "client sent \"Content-Length\" and "
+                              "\"Transfer-Encoding\" headers "
+                              "at the same time");
+                ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+                return NGX_ERROR;
+            }
+
             r->headers_in.chunked = 1;
 
         } else {