Attempt at a fix for #3344

This commit is contained in:
Ylian Saint-Hilaire 2021-12-13 16:29:18 -08:00
parent 22014f82b3
commit 40f052e027

View File

@ -4641,16 +4641,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
break; break;
} }
case 'twoFactorCookie': { case 'twoFactorCookie': {
// Do not allow this command when logged in using a login token try {
if (req.session.loginToken != null) break; // Do not allow this command when logged in using a login token
if (req.session.loginToken != null) break;
// Generate a two-factor cookie // Do not allows this command is 2FA cookie duration is set to zero
if (((domain.twofactorcookiedurationdays == null) || (domain.twofactorcookiedurationdays > 0))) { if (domain.twofactorcookiedurationdays === 0) break;
// Generate a two-factor cookie
var maxCookieAge = domain.twofactorcookiedurationdays; var maxCookieAge = domain.twofactorcookiedurationdays;
if (typeof maxCookieAge != 'number') { maxCookieAge = 30; } if ((typeof maxCookieAge != 'number') || (maxCookieAge < 1)) { maxCookieAge = 30; }
const twoFactorCookie = parent.parent.encodeCookie({ userid: user._id, expire: maxCookieAge * 24 * 60 /*, ip: req.clientIp*/ }, parent.parent.loginCookieEncryptionKey); const twoFactorCookie = parent.parent.encodeCookie({ userid: user._id, expire: maxCookieAge * 24 * 60 /*, ip: req.clientIp*/ }, parent.parent.loginCookieEncryptionKey);
try { ws.send(JSON.stringify({ action: 'twoFactorCookie', cookie: twoFactorCookie })); } catch (ex) { } try { ws.send(JSON.stringify({ action: 'twoFactorCookie', cookie: twoFactorCookie })); } catch (ex) { }
} } catch (ex) { console.log(ex); }
break; break;
} }
case 'amtsetupbin': { case 'amtsetupbin': {