fix(auto): use proper URL parsing in _is_local_url#742
Open
u7k4rs6 wants to merge 1 commit into
Open
Conversation
Replace naive substring matching with urlparse-based hostname extraction followed by exact string checks for "localhost"/"0.0.0.0" and ipaddress.ip_address().is_loopback for numeric addresses. Fixes three classes of failure: - False positive: "http://localhost.evil.com" no longer returns True - Missing 0.0.0.0 - Missing IPv6 loopback ::1 and the full 127.0.0.0/8 range
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.
Summary
Replace the naive substring matching in
AutoEnv._is_local_urlwithurllib.parse.urlparse-based hostname extraction, fixing three classes of failure:http://localhost.evil.comreturnedTruebecause"localhost"appeared as a substring; the proxy-bypass logic then applied to a hostile host.127.0.0.1was matched;127.x.x.xand the IPv6 loopback::1were not covered.The new implementation:
urlparseto extract the hostname (handles bracketed IPv6 automatically)."localhost"and"0.0.0.0".ipaddress.ip_address(hostname).is_loopbackfor all numeric addresses, covering127.0.0.0/8and::1.try/exceptso malformed URLs returnFalse.Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
New parametrized tests added to
tests/envs/test_auto_env.pyunderTestIsLocalUrl:http://localhost:8000Truehttp://127.0.0.1:8000Truehttp://127.5.5.5True(rest of 127.0.0.0/8)http://[::1]:8000True(IPv6 loopback)http://0.0.0.0:8000Truehttp://localhost.evil.comFalse(headline bug)http://my-127.0.0.1.ioFalsehttps://example.comFalsenot-a-urlFalseClaude Code Review
N/A