Upgrading socket.io packages#946
Conversation
There was a problem hiding this comment.
Thanks for this @chasen, this was on our to-do list. A few comments:
-
We don’t actually importActually this seems to cause TypeScript to fail to findsocket.iodirectly anywhere, this is done bykoa-socket-2, so we can removesocket.ioas a direct dependency.socket.io, so I guess we just need to make sure we install the same version askoa-socket-2uses? -
koa-socket-2still uses socket.io v3 (source), so we’d be using a v3 server with a v4 client. According to the socket.io v3 → v4 migration guide:a v3 client will be able to reach a v4 server and vice-versa
So this is probably OK, but maybe worth double checking?
-
As of socket.io v3, type definitions are bundled with the main packages (source), so we should remove the
@types/socket.ioand@types/socket.io-clientpackages. This does trigger some TypeScript errors though, which will need resolving. -
Most of the relevant breaking changes to socket.io (v3, v4) don’t seem to impact us but we do need to make some changes to handle how socket.io >3 handles CORS. If I run our examples (you can do this by running
npm startfrom the boardgame.io repo), all the multiplayer examples (except Tic-Tac-Toe > Multiplayer, which uses theLocalmultiplayer adapter rather than the socket server) are broken on this branch and print CORS errors to the browser console. Ideally we would provide a default set-up that continues working as currently, or give clear guidance on how to configure CORS and apply that guidance to these examples.
(As you can see, the tests can’t be entirely trusted when it comes to socket communications as in general one side or the other gets mocked in tests, so unfortunately a bit of manual testing is necessary until that’s improved.)
|
Sounds good, ill take a stab at updating these over the next few days |
|
@delucis PTAL... I think I addressed all your comments. Important to note a new "origins" param for the Server |
|
Thanks for taking this on @vdfdev! This all looks good and the examples are working as expected. One thought: do you think we should throw an error if the |
|
CVE-2020-36048 |
|
@larry801 The updates on this branch will bump the used engine.io version to 4.1.1 and that CVE lists the vulnerable versions as <4.0.0, so I guess merging this would resolve that? |
|
@vdfdev I noticed that the |
|
Hum, Nice, I didn't know it could be a regex. Maybe we can leave the local host with any port as the default? Thanks for adding the warning! |
I also considered that, but I guess the socket.io CORS default was chosen with security in mind, and requiring setting it gives us the chance to introduce the concept in the tutorial (instead of encountering it for the first time as yet another thing that breaks when deploying to a proper server). |
|
I agree with this trade-off... sounds good then! |
Socket.io latest version comes with some quality of life improvement that will help with the game development I am working on. So that we dont have to run a separate socket.io server and we could instead just hook into the main one used by the game it would be nice to be able to use these features.
All tests run and pass
Closes #945
Checklist
main).