From fa01801f645ea980f34a73eed5fb6596c80d1e57 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 2 Dec 2021 14:13:16 -0500 Subject: [PATCH] fix: don't throw on invalid session, just return early so socket is not opened. Also updated the plugin hook call to `static:sockets.validateSession` to not return a result, because in static calls that result is always null anyway --- src/socket.io/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 6d07cfa991..eeba1bf9b0 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -89,9 +89,9 @@ async function onConnect(socket) { } catch (e) { if (e.message === '[[error:invalid-session]]') { socket.emit('event:invalid_session'); - return; } - throw e; + + return; } if (socket.uid) { @@ -208,12 +208,12 @@ async function validateSession(socket, errorMsg) { if (!sessionData) { throw new Error(errorMsg); } - const result = await plugins.hooks.fire('static:sockets.validateSession', { + + await plugins.hooks.fire('static:sockets.validateSession', { req: req, socket: socket, session: sessionData, }); - return result; } const cookieParserAsync = util.promisify((req, callback) => cookieParser(req, {}, err => callback(err)));