You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When specifying a URI with an IPv6 address as the host, the Host header of the request contains the IPv6 address but it is not surrounded by brackets
e.g. With a locally running apache webserver, the following snippet results in an HTTP 400 Bad Request error because of the malformed host header (Host: ::1 instead of Host: [::1])
require 'net/http'
uri = URI.parse('http://[::1]')
Net::HTTP.get_response(uri)
I tried to debug this issue a little bit.
When URI is not used, the addr_port method is normally called.
Theaddr_port method handles wrapping an IPv6 address in brackets.
When a URI is used, we end up here, where req['host'] is set and that prevents addr_port from being called.
I don't know what the best fix would be, but having a single source of truth for handling the conversion of the 'host' header would probably help.
Edit:
How we end up with ::1 rather than [::1] is due to using #hostname (vs #host).
Activity
altruby commentedon Sep 18, 2023
I tried to debug this issue a little bit.
When URI is not used, the
addr_portmethod is normally called.The
addr_portmethod handles wrapping an IPv6 address in brackets.When a URI is used, we end up here, where
req['host']is set and that preventsaddr_portfrom being called.I don't know what the best fix would be, but having a single source of truth for handling the conversion of the 'host' header would probably help.
Edit:
How we end up with
::1rather than[::1]is due to using#hostname(vs#host).