From 0263b4daec87cf6677ecef87eb229d4e045d8732 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 3 Jan 2019 21:14:30 -0500 Subject: [PATCH] feat: added new hook `static:sockets.validateSession` (#7189) * feat: added new hook * fix: improper .bind() call, +req in static:sockets.validateSession * fix: restored original sessionStore logic, +hook original logic to retrieve the sessionStore was not faulty, but was changed for the sake of changing things, which ultimately led to issues with tests, etc. --- src/socket.io/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 1ced452877..91d660317d 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -10,6 +10,7 @@ var cookieParser = require('cookie-parser')(nconf.get('secret')); var db = require('../database'); var user = require('../user'); var logger = require('../logger'); +var plugins = require('../plugins'); var ratelimit = require('../middleware/ratelimit'); @@ -179,12 +180,17 @@ function validateSession(socket, callback) { if (!req.signedCookies || !req.signedCookies[nconf.get('sessionKey')]) { return callback(); } + db.sessionStore.get(req.signedCookies[nconf.get('sessionKey')], function (err, sessionData) { if (err || !sessionData) { return callback(err || new Error('[[error:invalid-session]]')); } - callback(); + plugins.fireHook('static:sockets.validateSession', { + req: req, + socket: socket, + session: sessionData, + }, callback); }); }