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

WebSocket WebSocket wildcard host errors #844

Closed
jonthn opened this issue Jan 2, 2019 · 4 comments
Closed

WebSocket WebSocket wildcard host errors #844

jonthn opened this issue Jan 2, 2019 · 4 comments

Comments

@jonthn
Copy link

jonthn commented Jan 2, 2019

Note that by filing an issue, you agree that you have read and agreed to
our contribution guidelines.

NNG & Platform details.

nng-1.1.1, Debian GNU/Linux 9.5 (Stretch)

Expected Behavior

When listening to ws://*:45454/foobar I would expect that :

  1. nng_dial to ws://localhost:45454/foobar works
  2. that this listen does on both IPv4 and IPv6 on localhost, and the same for external/LAN interface

The documentation, indeed seems to explain it's dependent of the underlying system but as I think it's a common setup for many OS, and that it works out-of-the-box on macOS, i'm wondering if I'm missing something.

To listen to all ports on the system, the host name may be elided from the URL on the listener. This will wind up listening to all interfaces on the system, with possible caveats for IPv4 and IPv6 depending on what the underlying system supports. (On most modern systems it will map to the special IPv6 address ::, and both IPv4 and IPv6 connections will be permitted, with IPv4 addresses mapped to IPv6 addresses.)

Actual Behavior

What happens is the listen is done only on IPv4 and the dial is using IPv6.

  1. Is there a way to specify that you only want IPv4 or IPv6 ?
  2. As IPv6 is now the preferred protocol and I would prefer a more transparent approach, is there something that can be done to avoid specifying/limit the IP protocol version ?
  3. It's an almost stock installation of Debian 9 but maybe the setup is incorrect and some configuration should be done ?
@gdamore
Copy link
Contributor

gdamore commented Feb 18, 2019

This seems like a request to support to ws4:// and ws6:// to get explicit binding like we have for TCP.

The problem with not specifying an address (using INADDR_ANY) is that the consequences of this are highly unportable. This probably does an AF_INET6 binding, and expects that the platform does a dual stack mapping (IPv4 mapped IPv6 address), but the support for this is hardly universal.

Btw, what "localhost" maps to is also highly platform specific. It usually maps to 127.0.0.1, but it might also map to ::1. Or it might not.

I would be willing to contemplate adding explicit binding options (ws4:// and ws://6, as well as the wss4:// and wss6:// options) for websocket. This would require enhancing the HTTP framework somewhat to support this as well.

To be completely honest, I think when binding you're best bet is to specify an actual host IP address or name. This is actually super important if you use TLS because we need the name to match to the certificate.

@janjaapbos
Copy link
Contributor

janjaapbos commented Feb 18, 2019 via email

@gdamore
Copy link
Contributor

gdamore commented Feb 18, 2019

Fair point @janjaapbos

@gdamore
Copy link
Contributor

gdamore commented Feb 18, 2019

It is possible to specify that different hostname via the nng_tls_config_* API, btw. It just takes extra effort.

@gdamore gdamore changed the title WebSocket IPv4 and IPv6 with wildcard host and localhost Connection refused WebSocket WebSocket wildcard host errors Jul 26, 2020
@gdamore gdamore added the bug label Jul 26, 2020
gdamore added a commit that referenced this issue Jul 26, 2020
fixes #1224 wss fails on IPV6 address

This fixes bugs and inconsistencies in the way addresses are
handled for HTTP (and consequently websocket).  The Host:
address line needs to look at numeric IPs and treat wildcards
as if they are not specified, and needs to understand the IPv6
address format using brackets (e.g. [::1]:80).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants