Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
fix(auth): guard two-fa client token decode and session restore
ANSHSINGH050404f72ca7f5e0ba
diff --git a/console/app/controllers/auth/two-fa.js b/console/app/controllers/auth/two-fa.jsindex c61ce73c..2a18bc9b 100644--- a/console/app/controllers/auth/two-fa.js+++ b/console/app/controllers/auth/two-fa.js@@ -241,8 +241,17 @@ export default class AuthTwoFaController extends Controller {* @returns {Date|null} - Date representing the expiration date, or null if invalid.*/getExpirationDateFromClientToken(clientToken) {+ if (!clientToken || typeof clientToken !== 'string') {+ return null;+ }+const decoder = new TextDecoder();- const binString = atob(clientToken);+ let binString;+ try {+ binString = atob(clientToken);+ } catch {+ return null;+ }const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0));const decodedString = decoder.decode(bytes);diff --git a/console/app/routes/auth/two-fa.js b/console/app/routes/auth/two-fa.jsindex e4170adb..988853ae 100644--- a/console/app/routes/auth/two-fa.js+++ b/console/app/routes/auth/two-fa.js@@ -28,7 +28,8 @@ export default class AuthTwoFaRoute extends Route {// validate 2fa session with serverlet { token, clientToken } = transition.to.queryParams;- return this.session.store.restore().then(({ identity }) => {+ return this.session.store.restore().then((restored) => {+ const { identity } = restored ?? {};if (!identity) {this.notifications.error('2FA failed to initialize.');return this.router.transitionTo('auth.login');@@ -59,12 +60,16 @@ export default class AuthTwoFaRoute extends Route {setupController(controller) {super.setupController(...arguments);- this.session.store.restore().then(({ clientToken, identity }) => {- controller.clientToken = clientToken;- controller.identity = identity;- controller.twoFactorSessionExpiresAfter = controller.getExpirationDateFromClientToken(clientToken);- controller.countdownReady = true;- });+ this.session.store+ .restore()+ .then((restored) => {+ const { clientToken, identity } = restored ?? {};+ controller.clientToken = clientToken;+ controller.identity = identity;+ controller.twoFactorSessionExpiresAfter = controller.getExpirationDateFromClientToken(clientToken);+ controller.countdownReady = true;+ })+ .catch(() => {});}async invalidateTwoFaSession(token, identity) {