]> git.kaiwu.me - nginx.git/commitdiff
Disabled duplicate "Host" headers (ticket #1724).
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 20 Feb 2020 13:51:07 +0000 (16:51 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 20 Feb 2020 13:51:07 +0000 (16:51 +0300)
Duplicate "Host" headers were allowed in nginx 0.7.0 (revision b9de93d804ea)
as a workaround for some broken Motorola phones which used to generate
requests with two "Host" headers[1].  It is believed that this workaround
is no longer relevant.

[1] http://mailman.nginx.org/pipermail/nginx-ru/2008-May/017845.html

src/http/ngx_http_request.c

index 9e64fd2934c91a17f670fce9b47c71ffe900c3f7..99fa6967d23c664e95286ac0acc0ac1010466acc 100644 (file)
@@ -1755,10 +1755,18 @@ ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h,
     ngx_int_t  rc;
     ngx_str_t  host;
 
-    if (r->headers_in.host == NULL) {
-        r->headers_in.host = h;
+    if (r->headers_in.host) {
+        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                      "client sent duplicate host header: \"%V: %V\", "
+                      "previous value: \"%V: %V\"",
+                      &h->key, &h->value, &r->headers_in.host->key,
+                      &r->headers_in.host->value);
+        ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+        return NGX_ERROR;
     }
 
+    r->headers_in.host = h;
+
     host = h->value;
 
     rc = ngx_http_validate_host(&host, r->pool, 0);