lucaspoffo / renet

Server/Client network library for multiplayer games with authentication and connection management made with Rust
Apache License 2.0
622 stars 66 forks source link

Handle wildcard source public IP addresses properly #101

Closed WarrenHood closed 11 months ago

WarrenHood commented 11 months ago

Fixes: #43

Hi. I believe this check is currently too strict, and we should also handle the wildcard server IP: 0.0.0.0.

This change checks if our public server IP is 0.0.0.0:<port>, and will only check the port if that is the case.

I tested this locally by binding to 0.0.0.0:5000, and setting the public IP to 0.0.0.0:5000 in my ServerConfig and was able to receive messages successfully by connecting to 127.0.0.1:5000. (If I were to port forward, it'd be accessible by ${public-ip}:5000 as well, for example)

Without this, it is quite painful needing to pass in the public IP address of the server, which can change. This doesn't really affect security much since you explicitly need to set your public IP to use this wildcard 0.0.0.0 which just makes testing much more convenient. This also would allow you to connect to your server using your local IP from 1 client, and using your public IP from another (which is currently impossible since we can only set 1 public address)

lucaspoffo commented 11 months ago

In the netcode standard and some discussions existing in the original implementation, wildcards is a no go. It opens for reusing valid tokens from one server in others. In #102 I made so when using unsecure connections this check is skipped, I also added a way to add multiple ip addresses to the server, so you can add your local and public address.