Join our Newsletter — 33% off our NHI Course
Home› Guides› Social Login and Account Linking Security Guide
Guide Customer Identity

Social Login and Account Linking Security Guide

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 15 min read
On this page

Social login is safe only if the relying party knows exactly which identity it is trusting, and most account takeovers in this area come from linking accounts on an email address instead. When a service lets people sign in with Google, Apple, Microsoft or another identity provider and also offers a local password, it has to decide when two identities belong to the same person. Get that decision wrong and an attacker can sit inside an account before the victim has even created it, or merge their way into an existing one. This guide covers how to key federated identities, when email verification can and cannot be trusted, the account pre-hijacking attack classes, safe linking and unlinking flows, and what to log. It is written for CIAM architects, application developers and security engineers who build or review consumer and business sign-in. For the wider customer identity picture see the Customer IAM (CIAM) Guide.

Key takeaways

  • Key every federated identity on issuer plus subject. The iss and sub pair is the stable identifier; email, username and UPN are display attributes that can change or be controlled by someone else.
  • Never auto-link on a matching email. Require an authenticated session on the existing account, and ideally a fresh authentication, before a new identity is attached.
  • Treat email_verified as a claim about the provider, not a fact. Whether you can trust it depends on whether that provider is authoritative for the domain, which differs between consumer, workforce and self-hosted providers.
  • Pre-hijacking is an account creation problem. Unverified sign-ups, sessions that survive a password reset and pending email changes all let an attacker prepare an account the victim later adopts.
  • Linking events are security events. Log, notify and make every link and unlink reversible, and keep at least one strong authenticator that does not depend on the social provider.

How social login and account linking work

Almost every modern social login is OpenID Connect (OIDC) on top of the OAuth 2.0 authorisation code flow. The relying party (RP) redirects the user to the provider, receives an authorisation code, swaps it for an ID token and then has to answer one question: which local account does this token belong to? There are three common models.

ModelHow the local account is foundMain riskWhen it fits
Federated onlyAccount created on first login and keyed on iss + subLock-in to one provider; recovery depends on the providerLow-risk apps, single provider, workforce SSO
Multiple providers, separate accountsEach provider identity gets its own account, no mergingDuplicate accounts and user confusion, but no linking takeoverSmall services where duplicates are cheap
Linked identitiesOne account with a list of linked iss + sub pairs plus optional password or passkeyInsecure linking and pre-hijackingMost consumer platforms and SaaS with mixed sign-in
Account resolutionExisting records (for example a customer database) matched to a new federated identity by attributesAttaching data to the wrong personMigrations, legacy customer bases, regulated onboarding

NIST SP 800-63C-4 (final, July 2025) describes this as binding a federated identifier to an RP subscriber account. It allows an account to be linked to more than one federated identifier, but states that the RP shall require an authenticated session with the subscriber account for all linking functions, and should require authentication with an existing federated identifier before linking a new one. When an identifier is removed, the RP must stop accepting it. See the NIST SP 800-63C-4 Federation Assurance Levels Guide.

Choosing the right identifier

The OIDC Core specification defines sub as a locally unique identifier that is never reassigned within the issuer. Uniqueness is scoped to the issuer: two providers can issue the same sub to different people. NIST SP 800-63C-4 Section 3.4 makes the same point, describing the federated identifier as the combination of subject and issuer and saying the RP must never process a subject identifier without accounting for the issuing IdP.

ClaimStable?Unique?Safe use
iss + subYes, never reassigned within the issuerYesPrimary key for the linked identity
tid + oid (Microsoft Entra ID)Yes, immutableYesMicrosoft recommends this combined key for application data and access decisions
emailNo, users and tenant administrators can change itNoDisplay, contact, a hint for suggested linking only
preferred_username, unique_nameNoNoDisplay only
upnNo, often changes over the user's lifetimeYes at a point in timeNot for authorisation
hd (Google Workspace)Yes for the accountIdentifies the hosted domainRestricting access to members of a specific Google Workspace domain
  • Microsoft Entra ID: Microsoft's claims validation guidance says never to use email, preferred_username or unique_name to decide access, because they are not unique and can be controlled by tenant administrators or sometimes users. Multi-tenant apps are the worst case: a user in one tenant can set a mail attribute that matches someone else's address.
  • Google: Google's ID token verification guide says to use only sub as the unique identifier, because one Google Account can have different email addresses over time.
  • Store the pair, not a hash of email: keep a linked-identities table with columns for issuer, subject, provider name, link date, linking method and last use. This also makes unlinking and incident response straightforward.

ASVS 5.0 requirement V10.5.2 captures this for OIDC clients: identify the user from claims that cannot be reassigned, usually sub, within the scope of the identity provider.

When email verification can be trusted

Linking on email is tempting because it removes duplicate accounts. The problem is that email_verified: true only tells you that the provider believes it verified the address at some point. Whether the provider is authoritative for that address is a separate question.

Provider situationIs the provider authoritative for the address?What to do
Google account with an @gmail.com addressYes, Google issues the mailboxEmail can be used as a strong hint, still link on sub
Google account with email_verified true and hd presentYes, per Google's guidance, it is a Workspace accountAs above
Google account with a non-Gmail address and no hdNo, Google says to use a password or other challenge even if email_verified is trueDo not auto-link; challenge the existing account
Microsoft Entra multi-tenant appOnly if the tenant has verified the domainNever trust email; Microsoft now strips unverified email claims by default for most apps (removeUnverifiedEmailClaim in authenticationBehaviors)
Self-hosted or enterprise OIDC providerOnly for domains its operator controlsAllow-list issuer and domain pairs explicitly
Provider that does not verify email at allNoTreat the email as unverified user input

Microsoft's authenticationBehaviors documentation describes exactly why this matters: email claims are open to privilege escalation when the mail attribute holds an address whose domain owner is not verified, and in multi-tenant apps where a user changes their mail attribute to reach resources in another tenant. Single-tenant apps and multi-tenant apps with prior sign-ins using unverified emails must opt in to the removal by setting removeUnverifiedEmailClaim to true.

A defensible rule: an email match may trigger a suggested link, where the user proves control of the existing account (password, passkey or an emailed one-time link to the address already on file) before the new identity is attached. Auth0's account linking documentation takes the same position, asking for authentication on both accounts before linking, whether linking is manual or automatic.

Account pre-hijacking attack classes

Sudhodanan and Paverd's USENIX Security 2022 paper "Pre-hijacked accounts" studied 75 popular services and found at least 35 vulnerable to at least one of five pre-hijacking attacks. The attacker needs only the victim's email address and acts before the victim signs up. Some variants were visible to an attentive user; others were not detectable from the victim's side at all.

Attack classWhat the attacker does firstWhy it worksControl
Classic-federated mergeRegisters a password account with the victim's emailLater social login with the same email is merged into the attacker's account, and the attacker's password still worksVerify email before the account is usable; on merge, invalidate local credentials not created by the verified owner
Unexpired sessionCreates an account and keeps a session openVictim "recovers" the account with a password reset but the attacker's session survivesTerminate all sessions and refresh tokens on password reset and on first verification
Trojan identifierCreates an account and links an attacker-controlled social identity or phone numberVictim adopts the account; the attacker keeps a back door loginShow and require review of all linked identities after recovery; clear unverified links
Unexpired email changeCreates an account with own email, starts a change to the victim's address, never confirmsVictim registers; attacker confirms the pending change laterExpire pending change tokens quickly; cancel them when the address is claimed elsewhere
Non-verifying IdPUses an identity provider that does not verify email to assert the victim's addressRP trusts the email from that provider and links or logs inAllow-list providers; trust email only from authoritative providers

The common root cause is that the service treats an account as owned by whoever holds the email address without having verified that at the moment it matters. CAPEC-21 (Exploitation of Trusted Identifiers) is the closest attack pattern entry, and the end state is ATT&CK T1078 Valid Accounts: the attacker signs in as a legitimate user. For the takeover side of the problem see the Account Takeover Prevention Guide.

Safe linking, unlinking and recovery flows

Linking

  1. Start from an authenticated session: linking is only offered inside a signed-in session on the existing account (NIST SP 800-63C-4 Section 3.8, OWASP Authentication Cheat Sheet).
  2. Step up: require a fresh authentication (for example within the last five minutes) with an existing authenticator before the link completes.
  3. Validate the new identity fully: run the complete ID token validation from OIDC Core Section 3.1.3.7: exact iss match, aud contains your client_id, signature, exp, and nonce matching the request (ASVS V10.5.1, V10.5.4).
  4. Refuse duplicates: if the iss + sub pair is already linked to another account, stop and route to support rather than moving it.
  5. Notify: send a notice to the verified address and existing devices that a new sign-in method was added (ASVS V6.3.7).

Suggested linking at first social login

  • Match found on email: tell the user an account exists and ask them to sign in to it first. Do not reveal more account detail than the sign-in page already does.
  • No match: create a new account keyed on the federated identifier.
  • Do not silently merge: silent merges are what the classic-federated merge attack relies on.

Unlinking and recovery

  • Last-method rule: do not allow the last sign-in method to be removed, and encourage a passkey or password that does not depend on the social provider so the user is not locked out if they lose that account. See the Passwordless and Passkeys Guide.
  • Block immediately: once an identity is unlinked, reject logins from it at once.
  • Recovery resets everything: a password reset or account recovery should end all sessions, revoke refresh tokens and present the list of linked identities for review. See the Account Recovery and Help Desk Security Guide.
  • Email changes: require re-authentication, confirm at the new address, notify the old address, and expire the pending change within a short window.

Protocol hygiene for the sign-in itself

Linking logic is only as safe as the OIDC integration underneath it. RFC 9700, the OAuth 2.0 Security Best Current Practice (January 2025), sets the baseline:

  • Exact redirect URI matching: authorisation servers must use exact string matching (ASVS V10.4.1); wildcards in redirect URIs enable code theft.
  • PKCE with S256: required for public clients and recommended for confidential ones.
  • CSRF protection: one-time state bound to the browser, or PKCE where the server is confirmed to support it; nonce for ID token replay.
  • Mix-up defence: an RP that talks to several providers (which is the definition of social login with more than one button) must defend against mix-up attacks, preferably by checking the iss response parameter defined in RFC 9207 against the issuer stored for that request, and aborting on mismatch.
  • No implicit flow: use the authorisation code flow; RFC 9700 says clients should not use response types that return access tokens in the front channel.
  • Library, not hand-rolled: both Google and OWASP recommend maintained OIDC libraries rather than custom token parsing.

See the OAuth 2.0 Security Best Current Practice (RFC 9700) Guide and the OAuth 2.0 and OpenID Connect Guide.

Decision guidance

  • One provider or many: each extra provider adds a mix-up surface and another email trust decision. Add providers your users actually hold, and keep an explicit issuer allow-list.
  • Consumer versus B2B: in B2B SaaS, customers expect tenant-level SSO. Bind each customer tenant to a specific issuer (and for Entra ID a specific tid) rather than accepting any work account whose email domain matches.
  • Small services: the simplest secure design is no automatic linking at all, plus a "connect another sign-in method" button inside account settings.
  • Large platforms: invest in suggested linking with step-up, a linked-identities admin view for support staff, and fraud signals at sign-up (velocity per email domain, disposable addresses). See the Identity Fraud Prevention Guide.
  • Regulated sectors: social login proves control of a provider account, not a real-world identity. Where identity assurance is required, add proofing separately (NIST 800-53 IA-12).

Detection and measurement

  • Log every identity event: account created (with method), identity linked, identity unlinked, email change requested, email change confirmed, password reset, all sessions revoked. Include issuer, subject, IP, device and whether step-up was satisfied.
  • Alert on patterns: a link followed within minutes by an email change or password change; a new identity linked from a new country; many sign-ups per hour sharing a provider or an email domain; pending email changes to addresses that already exist.
  • Support signals: tickets saying "someone else is in my new account" are the classic symptom of pre-hijacking and should be categorised separately.
MetricTarget or direction
Share of links completed with step-up authentication100%
Accounts usable before email verification0, or limited to non-sensitive functions
Median age of pending email change tokens at expiryHours, not days
Sessions surviving a password reset (test result)0
Code paths that key accounts on email (code review count)0
Accounts with only a social sign-in methodFalling, as users add a passkey

Framework mapping

FrameworkReferenceRelevance
NIST SP 800-63C-4Section 3.4 federated identifiers; Section 3.8 account linkingIssuer plus subject; authenticated session for linking
NIST SP 800-53 Rev. 5IA-8, IA-2, IA-12, AC-2, SI-4Authentication of non-organisational users, proofing, account management, monitoring
NIST CSF 2.0PR.AA-01, PR.AA-02, PR.AA-03, DE.CM-03Identity management, binding, authentication, monitoring
OWASP ASVS 5.0V10.5.1, V10.5.2, V10.5.4, V10.4.1, V6.3.6, V6.3.7Nonce, sub as identifier, audience, redirect matching, email not an authenticator, change notifications
MITRE ATT&CKT1078 Valid Accounts, T1586 Compromise AccountsOutcome and preparation of linking takeover
MITRE CAPECCAPEC-21 Exploitation of Trusted IdentifiersAbuse of email as a trusted identifier

Common failure patterns

  • Linking on email in the callback: the OIDC callback looks up users by email, so any provider that asserts the address gets in. Fix by keying on iss + sub and moving email matching into a suggested-link flow.
  • Usable unverified accounts: password sign-ups work before the address is confirmed, which is the starting point for most pre-hijacking classes.
  • Password reset that leaves sessions alive: the reset changes the password but not the refresh tokens or remembered devices.
  • Trusting email from every provider equally: a provider that does not verify email, or a multi-tenant workforce provider with unverified domains, is treated like Gmail.
  • Tenant SSO keyed on email domain: B2B apps that admit any Entra ID user whose address ends in the customer's domain instead of pinning the customer's tenant ID.
  • No notification on link: users never learn that a new sign-in method was added, so a Trojan identifier stays in place for months.

Practitioner checklist

  • Store linked identities as iss + sub pairs (or tid + oid for Entra ID) and remove every lookup by email from sign-in code.
  • Maintain an issuer allow-list and decide per issuer whether its email claim is authoritative.
  • Require an authenticated session and recent step-up for every link, and refuse to move an identity already linked elsewhere.
  • Block sensitive use of an account until its email is verified.
  • Revoke all sessions and refresh tokens on password reset, recovery and first verification.
  • Expire pending email changes quickly and cancel them when the target address registers.
  • Notify users on every link, unlink, email change and recovery, and show linked identities in account settings.
  • Implement RFC 9700 basics: exact redirect matching, PKCE S256, state and nonce, and RFC 9207 iss checking.
  • Test the five pre-hijacking scenarios in your QA suite before each release of sign-in code.

Standards and references

Related NHI Mgmt Group resources: Customer IAM (CIAM) Guide · Account Takeover Prevention Guide · SAML vs OIDC Guide · Federation and Trust Relationships Guide · Passkey Rollout Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org