ruby / ruby/uri

URI::Generic.use_proxy? cannot match IPv6 literal addresses in no_proxy

Open
#218 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
125
Forks
65
Avg merge
6h 4m
Merged PRs (30d)
2

Description

Summary

URI::Generic.use_proxy? silently ignores IPv6 literal addresses in no_proxy / NO_PROXY, causing IPv6 targets to always be proxied even when they should be excluded.

Root cause

The parsing regex in use_proxy? splits no_proxy entries on colons to extract an optional port:

no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port|

IPv6 addresses contain colons as part of their syntax (e.g. 2001:db8::1), so this regex mangles them; the address is split into fragments rather than parsed as a host. As a result:

  • Bare entries like 2001:db8::1 are never correctly captured into p_host
  • Bracketed entries like [2001:db8::1] are captured literally (with brackets) and never reach the IPAddr.new(p_host).include?(addr) check since IPAddr.new("[2001:db8::1]") raises InvalidAddressError
  • Bracketed entries with port like [2001:db8::1]:8080 are similarly broken

Reproduction

require 'uri'
require 'resolv'

# IPv6 target that should bypass the proxy
no_proxy = "2001:db8::1"
hostname  = "2001:db8::1"
addr      = Resolv.getaddress(hostname) rescue hostname
port      = 80

puts URI::Generic.use_proxy?(hostname, addr, port, no_proxy)
# Expected: false (should bypass proxy)
# Actual:   true  (incorrectly routes through proxy)

Expected behavior

All three real-world no_proxy formats for IPv6 should be recognized:

Format Example
Bare address 2001:db8::1
Bracketed (RFC 2732 / RFC 3986) [2001:db8::1]
Bracketed with port [2001:db8::1]:8080
CIDR 2001:db8::/32

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at URI::Generic.use_proxy? and inspect the no_proxy parsing regex shown in the issue. Reproduce the behavior with the supplied Ruby example, then verify that bare, bracketed, bracketed-with-port, and CIDR IPv6 entries are recognized while existing proxy matching still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.