What does a JWT's sub claim identify, and why is sub alone not a global user identifier?
answer
- The claims are statements about it
- Unique only where it came from
- Two issuers, one value, two people
- Never reassign, never change
- Email is a moving target
basics
~20 ssub names the principal the claims are about. It is only required to be unique within its issuer's namespace, so the identity key is the issuer and subject together — the same sub value from two issuers can mean two different people.
solid answer
~50 s`sub` is the subject: the principal the rest of the claims describe, usually a user and sometimes a service. The specification requires its value to be unique **either locally within the issuer's context or globally** — and issuers routinely choose the local option, emitting short internal identifiers. So `sub` on its own is ambiguous: `"1001"` from your own login service and `"1001"` from a partner identity provider are unrelated principals. The correct identity key for a stored account link is the pair **(`iss`, `sub`)**, which is exactly why systems that accept more than one issuer key their user records that way. A second rule follows from the same reasoning: choose a value that is stable and never reused. Email addresses and usernames fail both tests — they change and they can be reassigned to a different person — so linking on them silently hands one user's account to another.
code
json · 3 lines{ "iss": "https://login.example.com", "sub": "1001" }
{ "iss": "https://partner-idp.example.net", "sub": "1001" }go deeper
Recall that sub identifies the user or principal the token is about, and that it is an opaque string you compare exactly rather than parse.
Explain the local-uniqueness rule and why the identity key is the (iss, sub) pair, with a concrete example of two issuers emitting the same value.
Show you audit an identity provider's subject stability during integration and treat mutable or recycled subjects as an account-takeover risk, not a cosmetic detail.
Own the account-linking model: how identities from multiple issuers map to one internal user, how a provider migration is survived, and whether subjects are pairwise for privacy.
## What sub means The subject claim identifies the principal that the JWT's claims are statements about. The specification's own framing is that "the claims in a JWT are normally statements about the subject", which is the cleanest way to remember it: if the payload says `role: admin`, it is asserting that *the subject* is an admin. For an interactive session that principal is the end user; for machine-to-machine tokens it is commonly the calling client or service identity. ## The uniqueness rule and why it bites The requirement is that `sub` be unique *in the context of the issuer*, or globally unique. That is a weak guarantee by design, because forcing global uniqueness on every issuer would mean mandating UUIDs or URIs everywhere. In practice issuers take the local option and emit database identifiers, so subject values collide freely across issuers. The consequence is concrete. A service that accepts tokens from a corporate directory, a consumer identity provider and its own login service will see the value `"1001"` from all three, meaning three unrelated people. Storing users keyed on `sub` alone merges those accounts: whoever authenticates second inherits the first person's data. The fix is to treat the identity key as the **(issuer, subject)** pair — store both columns, key the unique constraint on both, and compare both on every lookup. That is why identity libraries and account-linking schemas are built around the pair rather than the subject alone. ## Stability: never let sub change The second property you need is that the value is durable. It should not change while the account exists, and it must never be reassigned to a different principal after the original is deleted. Two anti-patterns break this: - **Mutable identifiers as sub.** Email addresses and usernames are the usual offenders. A user changes their email and, to every relying service, becomes a brand-new person with an empty account — or worse, an old address is released and assigned to someone else, who then inherits the previous holder's records. - **Recycled database ids.** A table that reuses identifiers after deletion has the same effect on a smaller scale. The robust choice is an opaque, immutable, never-reused surrogate: a UUID or an internal id that is generated once and only ever retired. Note that this is a property of how the *issuer* mints subjects — a relying party cannot fix it and can only detect the damage after the fact, which is why it is worth asking about when integrating a new identity provider. ## Opacity and format The value is a string, and URI-shaped values are permitted, which is how some issuers achieve global uniqueness. Relying parties should treat it as **opaque**: do not parse it, do not infer a tenant from a prefix, do not assume it is numeric, and do not assume a length. Comparison is exact string comparison — no case folding, no trimming, no Unicode normalization; those transformations either merge distinct subjects or fail to match the same one. ## Privacy Because the payload is readable by anyone holding the token, `sub` is a disclosed identifier. Using a raw email address exposes personal data to every log and client that sees the token; using an internal database id exposes an enumerable key and hints at your data's size. An opaque random identifier avoids both, and issuers serving multiple relying parties sometimes go further by emitting a different subject value to each one so that two services cannot correlate the same user. ## What interviewers are checking That you know `sub` is the principal and not the token's purpose; that you can state the (`iss`, `sub`) pairing rule and why it exists; and that you recognize mutable or reusable identifiers as an account-takeover hazard rather than a cosmetic choice.
- Why is an email address a poor choice for sub?It is mutable and reusable. A user who changes address becomes an unknown principal to every relying party, losing access to their own data; and an address released and later reassigned lets a new person inherit the previous holder's account. A subject must be stable for life and never recycled.
- Should a relying party parse structure out of a sub value?No — treat it as opaque. Prefixes, numeric shape and length are issuer implementation details that can change without notice, and code that infers a tenant or a user type from the string breaks on the next issuer change. Compare it as an exact string and store it verbatim.
- Can the same person have different sub values at different services?Yes. An issuer serving several relying parties may deliberately emit a distinct subject value per party so those parties cannot correlate the same user across them. Each relying party still gets a stable value for itself — pairwise, not shared — which is a privacy feature, not an inconsistency.
saying these in an interview costs you the question
- Says sub describes the token's subject or purpose
- Keys user records on sub alone across issuers
- Uses email or username as the subject value
- Case-folds or trims sub before comparing
- Parses tenant or role information out of sub