reject legacy hex IPv4 literals in connector host resolution - #13436
Draft
arshsmith1 wants to merge 1 commit into
Draft
reject legacy hex IPv4 literals in connector host resolution#13436arshsmith1 wants to merge 1 commit into
arshsmith1 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13436 +/- ##
=======================================
Coverage 98.42% 98.42%
=======================================
Files 133 133
Lines 49747 49760 +13
Branches 2628 2628
=======================================
+ Hits 48961 48974 +13
Misses 662 662
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
TCPConnector._resolve_hostalready rejects legacy numeric IPv4 aliases (2130706433,017700000001,127.1) so they cannot be resolved past a connector-level host policy that only inspects the raw host string. That rejection is gated onis_ip_address(host), whose heuristic is":" in host or host.replace(".", "").isdigit(), so it only recognises the decimal-dotted forms. Hexadecimal literals like0x7f000001and0x7f.0.0.1are not seen as IPs at all, so they skip theis_canonical_ipv4_addressguard and go straight to the resolver, wheregetaddrinfo/inet_atonmaps them onto127.0.0.1.This adds a small
is_ipv4_literalhelper (backed bysocket.inet_aton, so it recognises every form the resolver accepts) and widens the connector guard to use it, closing the hex gap while leaving canonical addresses and real hostnames untouched.Are there changes in behavior for the user?
Only for the bypass case. Canonical dotted-quad IPs still short-circuit the resolver as before, and real hostnames still resolve normally. A hex/legacy numeric literal that is not canonical now raises
InvalidUrlClientError, matching what already happens for the decimal and octal forms.Is it a substantial burden for the maintainers to support this?
No. It reuses the existing guard and helper next to
is_canonical_ipv4_address, and the regression sits in the test that already covers the decimal/octal/short aliases.Related issue number
None.
Checklist
CONTRIBUTORS.txt-- already listedCHANGES/folder