Summary
A flaw in the login credentials provider allows an attacker to bypass password verification when a TOTP code is provided, potentially gaining unauthorized access to user accounts. This issue exists due to problematic conditional logic in the authentication flow.
Details
The vulnerability resides in the authorize() function within the credentials provider, specifically in the file packages/features/auth/lib/next-auth-options.ts. The critical flaw is in the authentication logic at lines 179-187, where password verification is skipped if a TOTP code is provided, even if other conditions are met. This leads to two distinct issues:
Scenario 1 - Bypass for Non-2FA Users
When an attacker submits a non-empty value for the totpCode field, password verification is skipped, as the logic evaluates to false when the totpCode is present. This scenario affects users who do not have 2FA enabled (the majority), allowing attackers to bypass both password and TOTP verification. The function then improperly proceeds to authenticate the user without further checks.
Scenario 2 - Reduced Security for 2FA Users
Even for users who have 2FA enabled, the presence of a totpCode causes the function to bypass password verification, reducing the security of the multi-factor authentication process. The TOTP code is validated, but without the password factor, leaving the account vulnerable to compromise if the TOTP code is known.
Vulnerable Code
packages/features/auth/lib/next-auth-options.ts:175-243
if (!user.password?.hash && user.identityProvider == IdentityProvider.CAL) {
throw new Error(ErrorCode.IncorrectEmailPassword);
}
if (user.password?.hash && !credentials.totpCode) {
const isCorrectPassword = await verifyPassword(credentials.password, user.password.hash);
if (!isCorrectPassword) {
throw new Error(ErrorCode.IncorrectEmailPassword);
}
}
if (user.twoFactorEnabled && credentials.backupCode) {
...
} else if (user.twoFactorEnabled) {
if (!credentials.totpCode) {
throw new Error(ErrorCode.SecondFactorRequired);
}
const isValidToken = totpAuthenticatorCheck(credentials.totpCode, secret);
if (!isValidToken) {
throw new Error(ErrorCode.IncorrectTwoFactorCode);
}
}
Potential Attack Method
In certain cases, simply providing a totpCode alongside the victim's email address could lead to unauthorized access, bypassing the password check entirely. The presence of this code, even if incorrect, can allow attackers to access accounts that don't have 2FA or bypass the password check for 2FA users.
Impact
This flaw could result in unauthorized access to sensitive user data, including calendars, meeting links, and personal information. For users without 2FA, attackers could gain access simply by knowing the victim's email address, making the attack easier to execute. Even for users with 2FA enabled, the compromised system allows attackers to bypass one factor of authentication, weakening security. Additionally, the flaw could be exploited to perform user enumeration and impersonation, allowing attackers to gain access to any account if they have sufficient privileges.
By modifying the system’s authentication flow to enforce proper verification of both the password and the TOTP code (if applicable), this vulnerability can be mitigated.
Summary
A flaw in the login credentials provider allows an attacker to bypass password verification when a TOTP code is provided, potentially gaining unauthorized access to user accounts. This issue exists due to problematic conditional logic in the authentication flow.
Details
The vulnerability resides in the
authorize()function within the credentials provider, specifically in the filepackages/features/auth/lib/next-auth-options.ts. The critical flaw is in the authentication logic at lines 179-187, where password verification is skipped if a TOTP code is provided, even if other conditions are met. This leads to two distinct issues:Scenario 1 - Bypass for Non-2FA Users
When an attacker submits a non-empty value for the
totpCodefield, password verification is skipped, as the logic evaluates to false when thetotpCodeis present. This scenario affects users who do not have 2FA enabled (the majority), allowing attackers to bypass both password and TOTP verification. The function then improperly proceeds to authenticate the user without further checks.Scenario 2 - Reduced Security for 2FA Users
Even for users who have 2FA enabled, the presence of a
totpCodecauses the function to bypass password verification, reducing the security of the multi-factor authentication process. The TOTP code is validated, but without the password factor, leaving the account vulnerable to compromise if the TOTP code is known.Vulnerable Code
packages/features/auth/lib/next-auth-options.ts:175-243Potential Attack Method
In certain cases, simply providing a totpCode alongside the victim's email address could lead to unauthorized access, bypassing the password check entirely. The presence of this code, even if incorrect, can allow attackers to access accounts that don't have 2FA or bypass the password check for 2FA users.
Impact
This flaw could result in unauthorized access to sensitive user data, including calendars, meeting links, and personal information. For users without 2FA, attackers could gain access simply by knowing the victim's email address, making the attack easier to execute. Even for users with 2FA enabled, the compromised system allows attackers to bypass one factor of authentication, weakening security. Additionally, the flaw could be exploited to perform user enumeration and impersonation, allowing attackers to gain access to any account if they have sufficient privileges.
By modifying the system’s authentication flow to enforce proper verification of both the password and the TOTP code (if applicable), this vulnerability can be mitigated.