SHEET 03blog/microsoft-sign-in-noauth/ REVISED 

Sign in with Microsoft and nOAuth: when the email claim isn't proof

How trusting the email claim from Microsoft sign-in let any Entra tenant sign in as an existing user, and how the fix links accounts by sub and verified email only.

Published
Length
3 min read

If your app offers “Sign in with Microsoft” on the common endpoint and links accounts by the email claim, any Entra tenant admin can sign in as your existing users. The email on a work account is whatever that tenant’s admin typed in. The attack is known as nOAuth. I found it in a multi-tenant SaaS while preparing enterprise SSO, and the fix shipped on its own, ahead of the SSO work.

What was wrong

Two things combined to make it possible.

The app used the common authority, so any Microsoft account could sign in: personal accounts and work accounts from every Entra tenant. That part is normal. It’s what “Sign in with Microsoft” usually means.

The callback then did what many OAuth callbacks do. It looked for a user already linked to this Microsoft sub. If there wasn’t one, it looked the user up by email and linked the Microsoft identity onto that account. Before linking, it checked whether the email was verified, like this:

const emailVerified =
  claims.email_verified === true ||
  (typeof claims.email_verified === "undefined" && Boolean(email));

Entra doesn’t send email_verified, so the second branch always applied, and every Microsoft email counted as verified. The email value could also fall back to preferred_username or upn, which are sign-in names and were never verified either.

So the path was short. An admin of any tenant creates a user, sets its email to a victim’s address, signs in to the app with Microsoft, and gets linked onto the victim’s account.

The fix

An email now counts as verified only when Microsoft vouches for it, and there are two ways it can:

  • The optional xms_edov claim is true. Microsoft sends it when the email domain’s owner has been verified, as a boolean or as "1".
  • The account is a personal Microsoft account, which you can tell from the tid claim. Personal accounts all share Microsoft’s fixed consumer tenant ID, 9188040d-6c67-4c5b-b112-36a304b66dad.
const edov = String(claims.xms_edov ?? "").trim().toLowerCase();
const emailVerified =
  emailClaim !== null &&
  (edov === "true" || edov === "1" || claims.tid === MICROSOFT_CONSUMER_TENANT_ID);

email_verified is now ignored entirely. Entra doesn’t send it, and a tenant with mapped claims enabled could inject it. The preferred_username and upn fallbacks still fill the email field, but they never count as verified.

The callback changed to match:

  • An account already linked by sub keeps signing in, whatever the email claim says. The sub is the identity, and the email is a hint.
  • An unverified Microsoft email that matches an existing account is refused. The user sees “An account with this email already exists. Sign in with your password or Google.”
  • A new account created from Microsoft sign-in stores the real verification result, so an unverified one can’t become a link target for Google sign-in later.

There was one deploy step: add xms_edov as an optional ID-token claim in the app registration, and never turn on acceptMappedClaims. Without the claim, work accounts are refused when they try to link onto an existing account by email, rather than trusted. Users who were already linked aren’t affected.

How it was tested

The callback tests run against a real Postgres database and stub only Microsoft’s token exchange, so each test controls the ID-token claims. One test signs in with an attacker’s sub and a victim’s email and checks that the request is refused and the victim’s account stays unlinked. A table of claim shapes pins the verification rule, including email_verified: true on its own (not verified) and upn plus xms_edov (not verified, because a sign-in name isn’t an email claim). Each test failed before the change.

The same audit closed two smaller ownership holes: an endpoint that returned plan details for any brand ID without an access check, and billing records and audit charges that landed on whoever clicked instead of the account’s owner.

What to check in your own app

  • Find where your OAuth callback links an identity onto an existing account by email. That line is where account takeover happens.
  • Key identities on the provider’s stable subject (sub, scoped to the issuer) instead of email.
  • Treat an email as verified only when the provider says so explicitly. A missing claim means “unknown”, not “yes”.
  • For Microsoft on common, request xms_edov and leave acceptMappedClaims off.
About the author

Software engineer and serial founder in Alexandria, Egypt, and CTO at Zaher.AI, a GEO and SEO agency serving MENA.

Console

Type help and press Enter.