diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f7f7f4..a0dfdd58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,3 +16,11 @@ Version 2.0.0 - The masterIP and masterPort config entries has been merged into masterURL. Breaks discordChat, playerManager, serverSelect, trainTeleports and clusterioModel. + + +Version 1.2.1 +------------- + +### Breaking Changes + +- Added authentication to the socket.io server running on the master. diff --git a/client.js b/client.js index 5d45d69b..cf62972d 100644 --- a/client.js +++ b/client.js @@ -603,7 +603,10 @@ async function instanceManagement(instanceconfig) { console.log("Started instanceManagement();"); /* Open websocket connection to master */ - var socket = ioClient(config.masterURL); + var socket = ioClient(config.masterURL+"?token="+config.masterAuthToken); + socket.on("error", err => { + console.log("SOCKET | Error: ", err); + }); socket.on("hello", data => { console.log("SOCKET | registering slave!"); socket.emit("registerSlave", { diff --git a/master.js b/master.js index 6e86dd4e..8fab7728 100644 --- a/master.js +++ b/master.js @@ -756,6 +756,18 @@ class wsSlave { } } +io.use((socket, next) => { + let token = socket.handshake.query.token; + authenticate.check(token).then((result) => { + if (result.ok) { + next(); + } else { + console.error(`SOCKET | authentication failed for ${socket.handshake.address}`); + next(new Error(result.msg)); + } + }); +}); + io.on('connection', function (socket) { // cleanup dead sockets from disconnected people let terminatedConnections = 0;