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;
}
case 'twoFactorCookie': {
try {
// Do not allow this command when logged in using a login token
if (req.session.loginToken != null) break;
// Do not allows this command is 2FA cookie duration is set to zero
if (domain.twofactorcookiedurationdays === 0) break;
// Generate a two-factor cookie
if (((domain.twofactorcookiedurationdays == null) || (domain.twofactorcookiedurationdays > 0))) {
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);
try { ws.send(JSON.stringify({ action: 'twoFactorCookie', cookie: twoFactorCookie })); } catch (ex) { }
}
} catch (ex) { console.log(ex); }
break;
}
case 'amtsetupbin': {