From: git@... Date: 2017-03-14T22:57:30+00:00 Subject: [ruby-core:80164] [Ruby trunk Bug#12642] Net::HTTP populates host header incorrectly when using an IPv6 Address Issue #12642 has been updated by andy (Andy Brody). File ipv6_test.rb added # Missing brackets from Host header for IPv6 addresses This is a regression from Ruby 2.1. The bug appears to have been introduced in ruby 2.2.0 by this commit: https://github.com/ruby/ruby/commit/70a2eb63999265ff7e8d46d1f5b410c8ee3d30d7 The change was added in response to this bug: https://bugs.ruby-lang.org/issues/10054 Attached is a test script demonstrating the bug "`ipv6_test.rb`". Correct behavior (present in 2.0 from 2.0.0-p643 onward and in 2.1 from 2.1.6 onward) for sending a request to `http://[::1]:8080` ~~~ Host: [::1]:8080 ~~~ Incorrect behavior (present in 2.2.0 through trunk) ~~~ Host: ::1:8080 ~~~ See also https://github.com/rest-client/rest-client/issues/583 I've added tests for rest-client that show the affected Ruby versions. `Net::HTTP` support for IPv6 URIs was broken in 2.0 before 2.0.0-p643 and 2.1 before 2.1.6, so there is a narrow window of versions that work. Full test output is here: https://travis-ci.org/rest-client/rest-client/builds/211090377 # Broken handling of explicit IPv6 Host header There is a separate bug that makes it impossible to explicitly set an IPv6 host header in affected ruby versions. Because Net::HTTP slices the end of the provided Host header after the first `:`, an IPv6 Host header will be rendered invalid. If you attempt to set `req['Host'] = '[::1]:8080'`, it will be rendered as `[` due to https://github.com/ruby/ruby/blob/v2_4_0/lib/net/http/generic_request.rb#L144 ~~~ $ ruby ipv6_test.rb --set-host /versions/2.3.1/lib/ruby/2.3.0/uri/generic.rb:595:in `check_host': bad component(expected host component): [ (URI::InvalidComponentError) from /versions/2.3.1/lib/ruby/2.3.0/uri/generic.rb:636:in `host=' from /versions/2.3.1/lib/ruby/2.3.0/net/http/generic_request.rb:151:in `update_uri' from /versions/2.3.1/lib/ruby/2.3.0/net/http.rb:1493:in `begin_transport' from /versions/2.3.1/lib/ruby/2.3.0/net/http.rb:1433:in `transport_request' from /versions/2.3.1/lib/ruby/2.3.0/net/http.rb:1407:in `request' from ipv6_test.rb:42:in `block in
' from /versions/2.3.1/lib/ruby/2.3.0/net/http.rb:853:in `start' ~~~ ---------------------------------------- Bug #12642: Net::HTTP populates host header incorrectly when using an IPv6 Address https://bugs.ruby-lang.org/issues/12642#change-63602 * Author: dcorbin (David Corbin) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- When sending a request, the client code adds a "Host" header. It does the by taking the given address, appending a colon, and then appending the port. This creates a fragment of a URL such as "google.com:80". However, when instead of "google.com", the address is an IPv6 address is given (such as 8383:3223::1333:DE12), simply appending a colon is not adequate. It yields 8383:3223::1333:DE12:80, which is hard to parse mess. RFC3986 stipulates that the host should be surrounded by square brackets, which would have the Host header as: [8383:3223::1333:DE12]:80. ---Files-------------------------------- ipv6_test.rb (985 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: