Skip to content

reject legacy hex IPv4 literals in connector host resolution - #13436

Draft
arshsmith1 wants to merge 1 commit into
aio-libs:masterfrom
arshsmith1:connector-reject-hex-ipv4
Draft

reject legacy hex IPv4 literals in connector host resolution#13436
arshsmith1 wants to merge 1 commit into
aio-libs:masterfrom
arshsmith1:connector-reject-hex-ipv4

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

What do these changes do?

TCPConnector._resolve_host already 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 on is_ip_address(host), whose heuristic is ":" in host or host.replace(".", "").isdigit(), so it only recognises the decimal-dotted forms. Hexadecimal literals like 0x7f000001 and 0x7f.0.0.1 are not seen as IPs at all, so they skip the is_canonical_ipv4_address guard and go straight to the resolver, where getaddrinfo/inet_aton maps them onto 127.0.0.1.

This adds a small is_ipv4_literal helper (backed by socket.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

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes -- N/A, the helper is internal and there is no public API change
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt -- already listed
  • Add a new news fragment into the CHANGES/ folder

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 17, 2026
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.42%. Comparing base (7dc43ae) to head (d86d782).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
Autobahn 21.97% <66.66%> (+0.01%) ⬆️
CI-GHA 98.32% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.09% <100.00%> (-0.01%) ⬇️
OS-Windows 96.45% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.34% <100.00%> (+<0.01%) ⬆️
Py-3.10 97.54% <100.00%> (+<0.01%) ⬆️
Py-3.11 97.79% <100.00%> (-0.01%) ⬇️
Py-3.12 97.88% <100.00%> (-0.01%) ⬇️
Py-3.13 97.87% <100.00%> (+<0.01%) ⬆️
Py-3.14 97.89% <100.00%> (+<0.01%) ⬆️
Py-3.14t 96.98% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 96.84% <100.00%> (-0.02%) ⬇️
VM-macos 97.34% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.09% <100.00%> (-0.01%) ⬇️
VM-windows 96.45% <100.00%> (+<0.01%) ⬆️
cython-coverage 82.19% <87.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 84 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing arshsmith1:connector-reject-hex-ipv4 (d86d782) with master (7dc43ae)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant