-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPAddr.new accepts invalid IPv6 addresses #52
Comments
Bisected the behavior change down to 09a6408 |
@HoneyryderChuck Can you explain why you think the address is invalid? Prior to the change, |
I see. The problem then is in Ruby's socket code then, as I can't setup a udp socket with the same ipv6 address (not on my laptop, will provide backtrace later). I was using ipaddr to eliminate "faulty" nameservers from the options provided by the system, but according to rhe bug report you linked, they're not faulty after all, it's just that UDPSocket can't deal with them. |
The change in behaviour comes from this code; prior to ruby 3.1, it was not accepting link-local IPv6 addresses such as "fe80::1213:31ff:fe67:8b94%en0". The subsequent issue that happens after the behaviour change is due to this line. Putting it in a small reproducible example: require "uri"
port = 53
uri = URI::Generic.build(scheme: "udp", port: port)
ip = "[fe80::1213:31ff:fe67:8b94%en0]"
uri.hostname = ip
# URI::InvalidComponentError: bad component(expected host component): [fe80::1213:31ff:fe67:8b94%en0] So the issue appears to be in EDIT: udp sockets have no problem with the ipv6 notation above: ip = IPAddr.new("[fe80::1213:31ff:fe67:8b94%en0]")
io = UDPSocket.new(ip.family)
io.sendmsg_nonblock("ping", 0, Socket.sockaddr_in(port, ip.to_s)) #=> 4 |
Section 3.2.2 of RFC 3986 states regarding use of IPv6 addresses in URIs:
So for RFC 3986 it's expected that URIs won't support IPv6 addresses with zone identifiers even though they are valid addresses. Looking at the relevant part of the WHATWG URL spec (https://url.spec.whatwg.org/#valid-ipv6-address-string), it refers to section 2.2 of RFC 4291, which also doesn't indicate support for IPv6 addresses with zone identifiers. In short, this doesn't appear to be a bug in either |
Oh, you're absolutely right, never thought that uris would not accept something considered valid for IPs. TIL. Thanks for the explanation. Will close the ticket. |
It was clarified in ruby/ipaddr#52 (comment) that there is no bug in `uri`, but rather that ipv6 addresses with zone-identifier aren't supposed to be used in uris.
It was clarified in ruby/ipaddr#52 (comment) that there is no bug in `uri`, but rather that ipv6 addresses with zone-identifier aren't supposed to be used in uris.
The text was updated successfully, but these errors were encountered: