fix: strip IPv6 zone ID from Host header per RFC 6874 section 4 - #13492
fix: strip IPv6 zone ID from Host header per RFC 6874 section 4#13492Archlie wants to merge 4 commits into
Conversation
When a request is made to a URL containing an IPv6 link-local address with a zone id (e.g. zone eth0), aiohttp sends the zone id verbatim as part of the Host header. Per RFC 6874 section 4, a zone id only has local significance to the sending host and must be stripped by the client. Servers that validate the Host header strictly against RFC 3986, such as nginx from 1.29.4 onward, reject such requests with 400 Bad Request. Strips the zone id from host_port_subcomponent and host_subcomponent before they are used in the Host header and CONNECT request target. Closes #13401
for more information, see https://pre-commit.ci
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported missing changelog attribution is present and follows the repository’s required syntax. Reviews (2): Last reviewed commit: "fix: preserve RST double-backtick format..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master aio-libs/aiohttp#13492 +/- ##
=======================================
Coverage 99.00% 99.00%
=======================================
Files 132 132
Lines 49626 49655 +29
Branches 2575 2577 +2
=======================================
+ Hits 49131 49161 +30
+ Misses 371 370 -1
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Note: the changelog attribution flagged by the greptile review is present in the latest commit — |
Per RFC 6874 section 4, a zone ID in an IPv6 link-local address has only local significance at the sending host and must be stripped by the client before sending the Host header:
Currently,
ClientRequestBase._update_headers()builds the Host header fromself.url.host_port_subcomponent, which preserves the zone ID (e.g.Host: [fe80::1%25eth0]:8080). Servers that validate the Host header strictly against RFC 3986, such as nginx from 1.29.4 onward, reject these requests with400 Bad Request.Changes
_strip_ipv6_zone_id()helper that removes the zone ID from bracketed IPv6 hosts (both literal%eth0and percent-encoded%25eth0forms)._update_headers()for the Host header.None.Reproduction
Before:
Host: [fe80::1%25eth0]:8080(rejected by nginx >= 1.29.4 with 400).After:
Host: [fe80::1]:8080.Closes aio-libs/yarl#1862.