fix: resolve localhost requests with IP literal URLs#289
Conversation
Follow-up to #276. The custom DNS lookup added in that PR is never invoked by Node.js when the URL contains a raw IP literal (127.0.0.1, [::1], 0.0.0.0) because Node skips DNS resolution for IPs entirely. Additionally, `new URL("http://[::1]:3000").hostname` returns `[::1]` (with brackets), so the original IPv6 hostname check never matched. Fix both issues by: 1. Comparing against the bracketed `[::1]` form and adding `0.0.0.0` 2. Rewriting IP literal URLs to the concrete working address when the hostname isn't already correct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughThe change modifies Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Follow-up to #276. The localhost DNS lookup fix from that PR doesn't work when the request URL contains a raw IP address (
127.0.0.1,[::1],0.0.0.0) instead of thelocalhosthostname. Two issues:Custom DNS lookup is skipped for IP literals. Node.js only calls the agent's
lookupfunction for hostnames — when the URL already contains an IP, it connects directly. Sohttp://127.0.0.1:3000bypasses the custom lookup entirely and always connects via IPv4, even if the server only listens on IPv6.IPv6 hostname check never matched.
new URL("http://[::1]:3000").hostnamereturns[::1](with brackets), but the code compared against::1(without brackets).This PR fixes both by:
[::1]form and also matching0.0.0.0checkConnection) when the current hostname won't connectTest plan
http://127.0.0.1:<port>against an IPv6-only local server — should succeedhttp://[::1]:<port>against an IPv4-only local server — should succeedhttp://0.0.0.0:<port>against both IPv4-only and IPv6-only servers — should succeedhttp://localhost:<port>— should continue working as beforehttp://example.com) — should not be intercepted🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes