The Tenant That Was Not Hers: Reading tid in a Microsoft ID Token
The challenge
A stranger signed in to Maya's Brieflane account. Read who issued the token, not who it names. Give the tenant ID that really issued it.
What you'll learn
- Read the issuer claims (iss, tid) of an Entra ID token
- Tell aud, oid, sub and tid apart
- Explain why the email claim is not an identity in a multi-tenant app
- Name the identifiers and checks that stop nOAuth
Skills tested
Prerequisites
- What a JWT is
- What Sign in with Microsoft (OAuth / OpenID Connect) does
How it works
An OpenID Connect ID token is a signed statement from an issuer saying who just signed in. With Microsoft Entra ID the issuer is a tenant, one organisation's directory: iss is https://login.microsoftonline.com/{tenant}/v2.0 and the same GUID is in tid. Every tenant's tokens are signed with the same Microsoft keys, so a valid signature proves the token came from a tenant, not from the one you expected.
Inside a tenant, a user is identified by oid (the object ID) and sub (unique per user and app). email is different: it is copied from the user's mail attribute, which the tenant's own admins can edit and which nobody has to verify. A multi-tenant app that maps the email in a token to an account lets any tenant admin sign in as anybody. Descope called this nOAuth in 2023.
Common mistakes
- Answering aud.
audis the client ID of Brieflane's own app registration: who the token is for, not who issued it. - Answering oid or sub. They identify the user object inside the issuing tenant, not the tenant.
- Answering tallis-advisory.example. Right tenant, wrong value: that is the domain in
preferred_username. The question asks for the tenant ID, the GUID intid. - Trusting the signature. RS256 with a Microsoft
kidonly proves Microsoft signed it for some tenant. The signature is genuine; the email is not.
How to defend against it
- Identify Microsoft users by
tid+oid(orsub), stored when the account is first linked. Never look an account up byemail,nameorpreferred_username. - Tie each customer organisation to its tenant ID and reject tokens whose
tidis not one of that customer's tenants. - If an email must be used, request the optional
xms_edovclaim and trust the email only when it istrue, and keep Entra ID'sremoveUnverifiedEmailClaimbehaviour on for the app registration (older registrations can still receive unverified emails). - Linking a new sign-in method to an existing account should require the existing method first.