“Sign in with Google” that logs people into any account with the same email (unsafe account linking)

Last updated November 17, 2026
Steps
- Find your sign-in callback (for example an Auth.js signIn or jwt callback, a Supabase auth hook, or your own /auth/callback route) and look for code that finds the user by email: getUserByEmail, findUnique({ where: { email } }) or a .eq("email", …) query.
- Store each external login in its own table keyed by provider plus the provider’s user ID (the sub claim; for Microsoft work accounts, tid plus oid), and look users up by that, not by email.
- Only link a new sign-in method to an existing account automatically when the provider says the email is verified (for Google, the email_verified claim) and the existing account’s email was verified in your app. Otherwise, ask the person to sign in with their original method first and add the new one from account settings.
- Auth.js (NextAuth): automatic linking between providers is off by default. Leave allowDangerousEmailAccountLinking off unless you trust that provider to have verified the email address.
- Supabase Auth links identities with the same email automatically and documents that linking to an unverified email would allow pre-account takeover. Keep email confirmation on for password signups, and use linkIdentity() for linking while signed in.
- Never grant roles from email alone, such as “anyone with an @ourcompany.com address is an admin.” Microsoft says the email claim isn’t guaranteed to be correct, can change, and should never be used for authorization.
- Test on your own app: in one browser, sign up with a password using an email you own but don’t verify it. In another, sign in with Google using that same email. You should not end up in the first account while its unverified password still works.
- Email the account owner whenever a new sign-in method is added, with a way to remove it.
Why it matters
Two things go wrong. First, if an attacker can get a provider to hand your app an email address they don’t own (some providers and setups return addresses that were never verified, and emails can be reassigned), email matching logs them into the real owner’s account. Second, in a pre-account takeover, the attacker signs up first with the victim’s email and a password, without verifying it; when the real owner later uses “Sign in with Google,” the app links the two and the attacker’s password still works. OpenID Connect Core says the email claim can be reused for different people over time and can change, which is why iss plus sub is the only guaranteed unique identifier. This page is for checking and fixing your own app.
Sources
OpenID Connect Core 1.0, section 5.7: Claim Stability and Uniqueness — https://openid.net/specs/openid-connect-core-1_0.html#ClaimStability
Google for Developers: OpenID Connect (Sign in with Google), ID token warning on email vs. sub — https://developers.google.com/identity/openid-connect/openid-connect
Microsoft identity platform: ID token claims reference (email claim) — https://learn.microsoft.com/en-us/entra/identity-platform/id-token-claims-reference
Supabase Docs: Identity Linking — https://supabase.com/docs/guides/auth/auth-identity-linking
Auth.js reference: providers, allowDangerousEmailAccountLinking — https://authjs.dev/reference/core/providers
Checked at the source on November 17, 2026.
Related patterns
- JWTs decoded but never verified
- Open redirects after login or OAuth callbacks
- Password reset flows that leak accounts or trust the Host header
- Login and signup messages that reveal which accounts exist (account enumeration)
- Sessions that stay valid after logout, password change or timeout
- Mass assignment: users can set fields like role or is_admin
FAQ
My app only has Google sign-in. Does this matter?
Yes, in a smaller way. Store and look up users by Google’s sub ID, not by email. Google says sub stays the same even if the person changes their email address, so email-keyed accounts can break or get mixed up.
Is linking accounts by email ever OK?
It can be, when the provider has verified the address and your existing account’s email was verified too. The safest pattern is to let a signed-in user add a new sign-in method from their settings.
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.