Skip to content
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

Incorrect Host header for IPv6 addresses #73

Open
AEtherC0r3 opened this issue Sep 29, 2022 · 1 comment
Open

Incorrect Host header for IPv6 addresses #73

AEtherC0r3 opened this issue Sep 29, 2022 · 1 comment

Comments

@AEtherC0r3
Copy link

AEtherC0r3 commented Sep 29, 2022

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)
@0x1eef
Copy link
Contributor

0x1eef commented Sep 18, 2023

I tried to debug this issue a little bit.
When URI is not used, the addr_port method is normally called.
The addr_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).

0x1eef added a commit to 0x1eef/net-http that referenced this issue Sep 19, 2023
Fix ruby#73:
Net::HTTP.get_response(URI.parse("http://[::1]"))
0x1eef added a commit to 0x1eef/net-http that referenced this issue Sep 19, 2023
Fix ruby#73:
Net::HTTP.get_response(URI.parse("http://[::1]"))
0x1eef added a commit to 0x1eef/net-http that referenced this issue Sep 19, 2023
Fix ruby#73:
Net::HTTP.get_response(URI.parse("http://[::1]"))

When the 'Host' header does not wrap an IPv6 address
in brackets, some servers (eg Apache) reject the request
with a 400 status code.
0x1eef added a commit to 0x1eef/net-http that referenced this issue Sep 19, 2023
Fix ruby#73:
Net::HTTP.get_response(URI.parse("http://[::1]"))

When the 'Host' header does not wrap an IPv6 address
in brackets, some servers (eg Apache) reject the request
with a 400 status code.
0x1eef added a commit to 0x1eef/net-http that referenced this issue Sep 19, 2023
Fix ruby#73:
Net::HTTP.get_response(URI.parse("http://[::1]"))

When the 'Host' header does not wrap an IPv6 address
in brackets, some servers (eg Apache) reject the request
with a 400 status code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants