]> git.kaiwu.me - nginx.git/commitdiff
Disabled control characters and space in header names.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 28 Jun 2021 15:01:18 +0000 (18:01 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 28 Jun 2021 15:01:18 +0000 (18:01 +0300)
Control characters (0x00-0x1f, 0x7f), space, and colon were never allowed in
header names.  The only somewhat valid use is header continuation which nginx
never supported and which is explicitly obsolete by RFC 7230.

Previously, such headers were considered invalid and were ignored by default
(as per ignore_invalid_headers directive).  With this change, such headers
are unconditionally rejected.

It is expected to make nginx more resilient to various attacks, in particular,
with ignore_invalid_headers switched off (which is inherently unsecure, though
nevertheless sometimes used in the wild).

src/http/modules/ngx_http_grpc_module.c
src/http/ngx_http_parse.c
src/http/v2/ngx_http_v2.c

index 654bd17b92364d2e8edf2945a734a783122a48bc..65bd1e6c34608f9ebcc798862035084792b12543 100644 (file)
@@ -3384,7 +3384,7 @@ ngx_http_grpc_validate_header_name(ngx_http_request_t *r, ngx_str_t *s)
             return NGX_ERROR;
         }
 
-        if (ch == '\0' || ch == CR || ch == LF) {
+        if (ch <= 0x20 || ch == 0x7f) {
             return NGX_ERROR;
         }
     }
index 0d36a44e5bb1547f4b793cd3a2bac83f24ff42a8..6af326deedd1ab890d8908eceb7077f284fe3598 100644 (file)
@@ -893,7 +893,7 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b,
                     break;
                 }
 
-                if (ch == '\0') {
+                if (ch <= 0x20 || ch == 0x7f || ch == ':') {
                     return NGX_HTTP_PARSE_INVALID_HEADER;
                 }
 
@@ -961,7 +961,7 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b,
                 break;
             }
 
-            if (ch == '\0') {
+            if (ch <= 0x20 || ch == 0x7f) {
                 return NGX_HTTP_PARSE_INVALID_HEADER;
             }
 
index 423667d47338deab68584819674aba29b7e3796b..3bef002bd719fbbc3ca81ae0962ce9c4215c3be9 100644 (file)
@@ -3457,7 +3457,7 @@ ngx_http_v2_validate_header(ngx_http_request_t *r, ngx_http_v2_header_t *header)
             continue;
         }
 
-        if (ch == '\0' || ch == LF || ch == CR || ch == ':'
+        if (ch <= 0x20 || ch == 0x7f || ch == ':'
             || (ch >= 'A' && ch <= 'Z'))
         {
             ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,