uwu / shelter

an attempt to prepare for the worst
https://shelter.uwu.network/
Creative Commons Zero v1.0 Universal
365 stars 12 forks source link

lune/dev: explicitly bind to IPv4 loopback #29

Closed tsumi7 closed 4 months ago

tsumi7 commented 4 months ago

Currently the HTTP server is started with an explicit host and the WebSocket Server is left to pick its own. This can result in IPv6 being preferred on the WebSocket server side when the WebSocket client points to IPv4 loopback explicitly.

This change fixes that by explicitly specifying the IPv4 loopback address. Alternate possible fixes include using localhost everywhere which makes no assumption about the IPv4 or IPv6 capabilities of the device (though requires localhost to point to the loopback, which mostly should be the case).

tsumi7 commented 4 months ago

Think I'm dumb.

Console:

$ netstat -ptlun | grep node
tcp        0      0 127.0.0.1:1112          0.0.0.0:*               LISTEN      2978061/node
tcp6       0      0 :::1211                 :::*                    LISTEN      2978061/node
$ curl -L4 127.0.0.1:1211
Upgrade Required
$ curl -L6 [::]:1211
Upgrade Required

Discord console:

WebSocket connection to 'ws://127.0.0.1:1211/' failed: 
(anonymous) @ bundle.js:6
Ds @ bundle.js:6
Ts @ bundle.js:6
onChange @ bundle.js:6
(anonymous) @ bundle.js:4
s @ VM3634 43455.25f3dd89fa027ef12b67.js:1
tsumi7 commented 4 months ago

Console check with wscat:

$ wscat --connect 127.0.0.1:1211
Connected (press CTRL+C to quit)
< {"TYPE":"update"}
$ wscat --connect [::]:1211
Connected (press CTRL+C to quit)
< {"TYPE":"update"}

I dunno. Then I just restarted discord and it connected the next time.

yellowsink commented 4 months ago

for reference: if you want to listen you should bind on either ::0, or 0.0.0.0. your system should definitely be clever enough to route calls to either way or the other via ipv4/6 translation layers. should not be an issue.