mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-20 03:48:47 +00:00
fix(login): MFA session validation to support multiple authentication methods (#10610)
Fixed an issue in `isSessionValid()` where users with multiple configured MFA methods (e.g., TOTP and U2F) would have their sessions incorrectly invalidated. The function previously used exclusive if-else logic that only checked the first matching method, causing validation to fail even when other configured methods were successfully verified. Closes #10529 # Which Problems Are Solved [#10529](https://github.com/zitadel/zitadel/issues/10529) # How the Problems Are Solved - Replaced exclusive if-else if chain with inclusive validation logic - Session is now considered valid if ANY configured MFA method has been verified - Improved error logging to show all configured methods and their verification status Example: A user with both TOTP and U2F configured can now successfully authenticate using either method, whereas previously the session would be invalid if they used U2F but TOTP was checked first.
This commit is contained in:
@@ -50,25 +50,22 @@ export async function isSessionValid({ serviceUrl, session }: { serviceUrl: stri
|
||||
});
|
||||
|
||||
const authMethods = authMethodTypes.authMethodTypes;
|
||||
if (authMethods && authMethods.includes(AuthenticationMethodType.TOTP)) {
|
||||
mfaValid = !!session.factors.totp?.verifiedAt;
|
||||
if (authMethods && authMethods.length > 0) {
|
||||
// Check if any of the configured authentication methods have been verified
|
||||
const totpValid = authMethods.includes(AuthenticationMethodType.TOTP) && !!session.factors.totp?.verifiedAt;
|
||||
const otpEmailValid = authMethods.includes(AuthenticationMethodType.OTP_EMAIL) && !!session.factors.otpEmail?.verifiedAt;
|
||||
const otpSmsValid = authMethods.includes(AuthenticationMethodType.OTP_SMS) && !!session.factors.otpSms?.verifiedAt;
|
||||
const u2fValid = authMethods.includes(AuthenticationMethodType.U2F) && !!session.factors.webAuthN?.verifiedAt;
|
||||
|
||||
mfaValid = totpValid || otpEmailValid || otpSmsValid || u2fValid;
|
||||
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid totpEmail factor", session.factors.totp?.verifiedAt);
|
||||
}
|
||||
} else if (authMethods && authMethods.includes(AuthenticationMethodType.OTP_EMAIL)) {
|
||||
mfaValid = !!session.factors.otpEmail?.verifiedAt;
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid otpEmail factor", session.factors.otpEmail?.verifiedAt);
|
||||
}
|
||||
} else if (authMethods && authMethods.includes(AuthenticationMethodType.OTP_SMS)) {
|
||||
mfaValid = !!session.factors.otpSms?.verifiedAt;
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid otpSms factor", session.factors.otpSms?.verifiedAt);
|
||||
}
|
||||
} else if (authMethods && authMethods.includes(AuthenticationMethodType.U2F)) {
|
||||
mfaValid = !!session.factors.webAuthN?.verifiedAt;
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid u2f factor", session.factors.webAuthN?.verifiedAt);
|
||||
console.warn("Session has no valid MFA factor. Configured methods:", authMethods, "Session factors:", {
|
||||
totp: session.factors.totp?.verifiedAt,
|
||||
otpEmail: session.factors.otpEmail?.verifiedAt,
|
||||
otpSms: session.factors.otpSms?.verifiedAt,
|
||||
webAuthN: session.factors.webAuthN?.verifiedAt
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// only check settings if no auth methods are available, as this would require a setup
|
||||
|
||||
Reference in New Issue
Block a user