From 0e4e8cc37e35cdcbd30df81c98b53ce9768c5e7d Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Thu, 5 Nov 2026 06:27:39 -0300 Subject: [PATCH] fix(ui): hold recovery codes before the activation request Activation ends the session while the reply is on its way, so a 401 elsewhere in the page could leave before the codes arrived. Co-Authored-By: Claude Opus 5.5 --- apps/gui/ui/account.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/gui/ui/account.js b/apps/gui/ui/account.js index 0782d03..5a50aba 100644 --- a/apps/gui/ui/account.js +++ b/apps/gui/ui/account.js @@ -196,12 +196,20 @@ function bindMfa() { $('#mfaEnroll').addEventListener('submit', (event) => { event.preventDefault(); attempt(status, async () => { - const reply = await withReauth(() => api('/api/auth/enroll/confirm', { - method: 'POST', - body: { code: $('#mfaCode').value.trim() }, - })); - // This session has just ended, and the page must not leave with the codes. + // Activation ends this session while the reply is on its way: a request + // from elsewhere in the page can get a 401 and leave before it lands, + // taking the codes with it. So the page is held before the POST. holdCodes(); + let reply; + try { + reply = await withReauth(() => api('/api/auth/enroll/confirm', { + method: 'POST', + body: { code: $('#mfaCode').value.trim() }, + })); + } catch (error) { + releaseCodes(); + throw error; + } $('#mfaEnroll').hidden = true; $('#mfaQr').removeAttribute('src'); $('#mfaKey').value = '';