]> git.kaiwu.me - nginx.git/commitdiff
HTTP/2: reject requests with out-of-order pseudo-headers
authorSergey Kandaurov <pluknet@nginx.com>
Wed, 15 Jul 2026 11:08:30 +0000 (15:08 +0400)
committerSergey Kandaurov <s.kandaurov@f5.com>
Wed, 15 Jul 2026 12:58:20 +0000 (16:58 +0400)
Handling of pseudo-headers is refactored to be more in line with
HTTP/3 implementation, that is, a request line is now constructed
as soon as pseudo-headers are followed by regular fields.  Here
this plugs a missing handling for absent mandatory or out-of-order
pseudo-headers.

Such requests are now rejected immediately as malformed.

Closes: https://github.com/nginx/nginx/issues/1526
src/http/v2/ngx_http_v2.c

index f8f87672557490d21378f7864444bea1bb2357ab..ebf724d8eee5d1cb6410dc54e215a21edadec8b9 100644 (file)
@@ -1803,6 +1803,10 @@ ngx_http_v2_state_process_header(ngx_http_v2_connection_t *h2c, u_char *pos,
         return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
     }
 
+    if (ngx_http_v2_construct_request_line(r) != NGX_OK) {
+        goto error;
+    }
+
     if (r->invalid_header) {
         cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
 
@@ -3303,6 +3307,13 @@ ngx_http_v2_pseudo_header(ngx_http_request_t *r, ngx_http_v2_header_t *header)
     header->name.len--;
     header->name.data++;
 
+    if (r->request_line.len) {
+        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                      "client sent out of order pseudo-headers");
+
+        return NGX_DECLINED;
+    }
+
     switch (header->name.len) {
     case 4:
         if (ngx_memcmp(header->name.data, "path", sizeof("path") - 1)
@@ -3577,6 +3588,10 @@ ngx_http_v2_construct_request_line(ngx_http_request_t *r)
 
     static const u_char ending[] = " HTTP/2.0";
 
+    if (r->request_line.len) {
+        return NGX_OK;
+    }
+
     if (r->method_name.len == 0
         || r->schema.len == 0
         || r->unparsed_uri.len == 0)