The two claims meant for this job
OpenID Connect gives every signed-in account two claims for telling users apart. iss names the issuer, and sub is the subject identifier that issuer gives the account. The core specification says this pair is the only thing a relying party can rely on as a stable identifier. It also says an issuer may reuse an email address, so email must not be used as a unique identifier (OpenID Connect Core 1.0, section 5.7).
Google says the same in its own guidance. Its sub is unique among Google accounts and never reused. It does not change, even when the user changes their email. Google's words on email are plain: "Don't use the email field as a unique identifier for a user" (Google, OpenID Connect).
What breaks when you match on email
The address changes
Gmail users can now change their address. When they do, Google keeps the same sub. A grant made before the change keeps returning the old address. Once the user revokes it, Google sends the new one, and an app that looks the user up by email finds nobody and creates a second account. Google names the result itself: "duplicate accounts and loss of access to existing data" (Google Developers Blog, 2 April 2026).
This has already been fixed in the open. The ztnet maintainer merged "Prevent duplicate OAuth accounts after email rename (Gmail)" on 14 April 2026, after an issue we opened. gogcli made sub the canonical key and kept the email as an alias, then moved renamed accounts across (gogcli #504).
The address belongs to someone else
The second failure is worse. Some providers let a user put an address on their account without proving they own it, and some addresses get reissued to a new person. An app that matches on email then signs that person in to the owner's account.
There are public cases. In 2023 Descope showed that apps trusting the email claim from Microsoft Entra ID could be taken over this way, a flaw it called nOAuth (BleepingComputer). In 2026 the AshAuthentication library for Elixir fixed the same flaw in its OAuth2 and OIDC strategies as CVE-2026-49757, rated 9.2 critical and reported by jarlah. The attack needed a provider that does not verify email ownership or lets an address be reclaimed, and the library's defaults were exposed.
The lookup to change
The bug usually sits in one line of the sign-in callback. Here it is in a Passport.js handler for Google, where profile.id is Google's sub:
// Finds the account by email: breaks on a rename,
// and trusts whoever holds the address
const user = await User.findOne({ email: profile.emails[0].value })
// Finds the account by issuer and subject
const identity = await Identity.findOne({
iss: 'https://accounts.google.com',
sub: profile.id,
})
Google writes the issuer as either https://accounts.google.com or accounts.google.com, so treat the two as the same issuer before you store or compare it (Google, OpenID Connect).
If you use Auth.js, it already links accounts by provider and account ID, and it leaves email linking off by default. Keep allowDangerousEmailAccountLinking off unless you trust the provider to have verified the address (Auth.js docs).
Moving existing users across
- Add an identities table with one row per
issandsubpair, each row pointing at a user. Make the pair unique. - On sign-in, look up the pair first. If it exists, that is the user, whatever the email says today.
- If the pair is new and an existing user has the same email, link the two only when the provider has verified the address (
email_verifiedis true) and the provider issues that address itself, as Google does for Gmail. Otherwise ask the user to sign in with their existing method first. Then write the pair, and never match that user on email again. - Keep the email as a contact detail, and update it when it changes.
Check your own code
authdrift is our open-source Semgrep ruleset for this pattern, under the MIT licence. It has six rules, written for Google sign-in, covering:
- Passport.js
- NextAuth
- Django and SQLAlchemy
- authlib
- Firebase Auth
- Lucia
Run it with Semgrep against your code:
git clone https://github.com/Neelagiri65/authdrift
semgrep --config authdrift/src/authdrift/rules/ ./your-app
Each match is a place where a sign-in handler looks a user up by email. Read each one: some will be email used for display or a password reset, which is fine. On its own test files the ruleset flags all 11 vulnerable samples and none of the 11 safe ones.
In April 2026 we ran these patterns across Sourcegraph's public code index. They matched 124 repositories in four Google sign-in ecosystems: 73 using Passport.js, 19 Ruby OmniAuth, 17 NextAuth and 15 Python. These are places where code references email as an identity field. We read three by hand, so treat the count as a map of where to look. Among 150 Passport.js projects, 9 referenced only the email and 51 only the Google ID. It is a snapshot, and several projects have moved to sub since.
If you would like a second pair of eyes on your sign-in code, we run identity audits. Write to [email protected].