From 292a40829feefda98c8509dcdbbb4a57af9bd6a6 Mon Sep 17 00:00:00 2001
From: SunandM <sunandm22@gmail.com>
Date: Mon, 3 Aug 2026 13:28:23 +0200
Subject: [PATCH] reject duplicate Host headers in request headers

Duplicate Host headers are now rejected with a ProtocolError.
This addresses a request smuggling primitive where a consumer
downgrading HTTP/2 to HTTP/1.1 would emit two Host header lines,
causing backend divergence (CWE-444).

The _validate_host_authority_header() function now counts Host
headers and raises ProtocolError if more than one is present,
covering both the receive path (_check_host_authority_header)
and the send path (_check_sent_host_authority_header).
---
 src/h2/utilities.py | 3 +++
 1 file changed, 3 insertions(+)

Index: h2-4.2.0/src/h2/utilities.py
===================================================================
--- h2-4.2.0.orig/src/h2/utilities.py
+++ h2-4.2.0/src/h2/utilities.py
@@ -456,6 +456,9 @@ def _validate_host_authority_header(head
         if header[0] == b":authority":
             authority_header_val = header[1]
         elif header[0] == b"host":
+            if host_header_val is not None:
+                msg = "Request header block has multiple Host headers."
+                raise ProtocolError(msg)
             host_header_val = header[1]
 
         yield header
Index: h2-4.2.0/tests/test_invalid_headers.py
===================================================================
--- h2-4.2.0.orig/tests/test_invalid_headers.py
+++ h2-4.2.0/tests/test_invalid_headers.py
@@ -43,6 +43,7 @@ class TestInvalidFrameSequences:
         [*base_request_headers, ("transfer-encoding", "gzip")],
         [*base_request_headers, ("upgrade", "super-protocol/1.1")],
         [*base_request_headers, ("te", "chunked")],
+        [*base_request_headers, ("host", "example.com"), ("host", "evil.example.com")],
         [*base_request_headers, ("host", "notexample.com")],
         [*base_request_headers, (" name", "name with leading space")],
         [*base_request_headers, ("name ", "name with trailing space")],
