fix cookieEncoding hex for 2fa #6096

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed May 18, 2024 at 19:45 UTC 323ef2d50a17b16965dc89bbb65f9394551bb2b4
1 file changed +2 -2
meshcentral.js
+2 -2
@@ -3575,7 +3575,7 @@ function CreateMeshCentralServer(config, args) {
3575 try {
3576 const iv = Buffer.from(obj.crypto.randomBytes(12), 'binary'), cipher = obj.crypto.createCipheriv('aes-256-gcm', key.slice(0, 32), iv);
3577 const crypted = Buffer.concat([cipher.update(JSON.stringify(data), 'utf8'), cipher.final()]);
3578 - return Buffer.concat([iv, cipher.getAuthTag(), crypted]).toString(obj.args.cookieencoding ? obj.args.cookieencoding : 'base64');
3578 + return Buffer.concat([iv, cipher.getAuthTag(), crypted]).toString(obj.args.cookieencoding ? obj.args.cookieencoding : 'base64').replace(/\+/g, '@').replace(/\//g, '$');
3579 } catch (ex) { return null; }
3580 }
3581
@@ -3584,7 +3584,7 @@ function CreateMeshCentralServer(config, args) {
3584 if ((typeof data != 'string') || (data.length < 13)) return {};
3585 if (key == null) { key = obj.loginCookieEncryptionKey; }
3586 try {
3587 - const buf = Buffer.from(data, 'base64');
3587 + const buf = Buffer.from(data.replace(/\@/g, '+').replace(/\$/g, '/'), obj.args.cookieencoding ? obj.args.cookieencoding : 'base64');
3588 const decipher = obj.crypto.createDecipheriv('aes-256-gcm', key.slice(0, 32), buf.slice(0, 12));
3589 decipher.setAuthTag(buf.slice(12, 28));
3590 return JSON.parse(decipher.update(buf.slice(28), 'binary', 'utf8') + decipher.final('utf8'));