From 1568a36a38318d3c227b92c5648956fc32ddb522 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 23 May 2022 16:45:44 -0700 Subject: [PATCH] 2FA cookie improvements. --- src/MainForm.cs | 1 + src/MeshCentralServer.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index cbe586c..c8a0554 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -1076,6 +1076,7 @@ namespace MeshCentralRouter cookieRefreshTimer.Enabled = true; // If we need to remember the 2nd factor, ask for a cookie now. + if (debug) { try { File.AppendAllText("debug.log", "Requesting 2FA cookie\r\n"); } catch (Exception) { } } if (tokenRememberCheckBox.Checked) { meshcentral.sendCommand("{\"action\":\"twoFactorCookie\"}"); } // Setup single instance pipe server diff --git a/src/MeshCentralServer.cs b/src/MeshCentralServer.cs index a2363e7..b9a0adb 100644 --- a/src/MeshCentralServer.cs +++ b/src/MeshCentralServer.cs @@ -676,8 +676,11 @@ namespace MeshCentralRouter { if (jsonAction.ContainsKey("cookie")) { - string cookie = (string)jsonAction["cookie"]; - if (onTwoFactorCookie != null) { onTwoFactorCookie(cookie); } + if (jsonAction["cookie"] == null) return; + if (jsonAction["cookie"].GetType() != typeof(string)) return; + string cookie = null; + try { cookie = (string)jsonAction["cookie"]; } catch (Exception) { } + if ((cookie != null) && (onTwoFactorCookie != null)) { onTwoFactorCookie(cookie); } } break; }