Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

delete email cooldown on success

Thiago Araujo da Silvaf6b43041155f
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 024e36402c..82cf221c04 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -160,7 +160,7 @@ export const KeyStoreTtls = {
AccessTokenStatusUpdateInSeconds: 120,
ProjectPermissionMarkerTtlSeconds: 10, // 10 seconds - short-lived marker for fingerprint validation
ProjectPermissionDataTtlSeconds: 600, // 10 minutes - longer-lived data payload
- MfaSessionInSeconds: 300, // 5 minutes
+ MfaSessionInSeconds: 600, // 10 minutes
MfaCodeResendCooldownInSeconds: 60, // 1 minute
WebAuthnChallengeInSeconds: 300, // 5 minutes
diff --git a/backend/src/server/routes/mfa-step-up-fns.ts b/backend/src/server/routes/mfa-step-up-fns.ts
index 0c7a0b91ce..1c12c90dc7 100644
--- a/backend/src/server/routes/mfa-step-up-fns.ts
+++ b/backend/src/server/routes/mfa-step-up-fns.ts
@@ -8,7 +8,7 @@ import { MfaMethod } from "@app/services/auth/auth-type";
//
// Viewing recovery codes, rotating recovery codes, and disabling MFA are all
// MFA-management actions of comparable risk, so they intentionally share a single
-// resource id: one fresh challenge covers all of them for the session TTL (5 min)
+// resource id: one fresh challenge covers all of them for the session TTL (10 min)
// rather than re-prompting the user for each action in quick succession.
//
// Enabling MFA is kept on its own resource id (never folded into MfaManagement):
@@ -27,7 +27,7 @@ export type TMfaStepUpResource = (typeof MfaStepUpResource)[keyof typeof MfaStep
* action, reusing the Redis-backed step-up MFA session primitive (mirrors the PAM
* account-access flow).
*
- * A verified session is reusable for the remainder of its TTL (5 min) and is bound
+ * A verified session is reusable for the remainder of its TTL (10 min) and is bound
* to `resourceId`, so it cannot be replayed against a different action.
*
* - With a valid, verified session for this user + resource: returns immediately.
diff --git a/backend/src/services/mfa-session/mfa-session-service.ts b/backend/src/services/mfa-session/mfa-session-service.ts
index f3d2803e42..cd85a9857e 100644
--- a/backend/src/services/mfa-session/mfa-session-service.ts
+++ b/backend/src/services/mfa-session/mfa-session-service.ts
@@ -158,6 +158,10 @@ export const mfaSessionServiceFactory = ({
await mfaLockoutService.resetStepUpMfaLockStatus(userId);
+ if (mfaMethod === MfaMethod.EMAIL) {
+ await keyStore.deleteItem(KeyStorePrefixes.MfaCodeResendCooldown(userId));
+ }
+
mfaSession.status = MfaSessionStatus.ACTIVE;
await updateMfaSession(mfaSession, KeyStoreTtls.MfaSessionInSeconds);
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/useMfaStepUp.ts b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/useMfaStepUp.ts
index 575d8b83d8..a0b8896ffb 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/useMfaStepUp.ts
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/useMfaStepUp.ts
@@ -12,11 +12,38 @@ const MFA_TIMEOUT = 5 * 60 * 1000;
// The most recently verified step-up MFA session id, shared across every
// useMfaStepUp instance. The MFA-management actions (view/rotate recovery codes,
// disable MFA) live in sibling components with their own hook instances but the
-// backend accepts one step-up session for all of them, so remembering the id in
-// module scope lets a challenge completed for one action satisfy the next until it
-// expires. It never drives rendering, and a stale id (e.g. after logout) is
-// harmless: the backend rejects it and a fresh challenge transparently re-runs.
-const sharedStepUpSession = { id: null as string | null };
+// backend accepts one step-up session for all of them, so remembering the id lets a
+// challenge completed for one action satisfy the next until it expires. It never
+// drives rendering, and a stale id (e.g. after logout, or a reload past the backend
+// TTL) is harmless: the backend rejects it and a fresh challenge transparently re-runs.
+//
+// Persisted in sessionStorage (not just module scope) so a full page reload doesn't
+// throw away a session the backend still considers active — otherwise every reload
+// forced a brand-new challenge even though the 10-minute window had not elapsed. It is
+// tab-scoped and cleared when the tab closes.
+const STEP_UP_SESSION_STORAGE_KEY = "mfaStepUpSessionId";
+
+const sharedStepUpSession = {
+ get id(): string | null {
+ try {
+ return sessionStorage.getItem(STEP_UP_SESSION_STORAGE_KEY);
+ } catch {
+ return null;
+ }
+ },
+ set id(value: string | null) {
+ try {
+ if (value) {
+ sessionStorage.setItem(STEP_UP_SESSION_STORAGE_KEY, value);
+ } else {
+ sessionStorage.removeItem(STEP_UP_SESSION_STORAGE_KEY);
+ }
+ } catch {
+ // Storage can be unavailable (private mode, blocked cookies); degrade to always
+ // re-challenging rather than crashing.
+ }
+ }
+};
// An action guarded by step-up MFA. It receives the verified session id (once
// available) so it can replay itself against the backend. When the backend