opyeb JWTScope

Guides · Token basics

iss, aud and sub: the three names that stop a valid token being used in the wrong place

Updated 28 Nov 2026 · 7 min read

A signature check answers whether the token was produced by the holder of a key. It does not answer whether the token was meant for your service. That is the job of iss (issuer), aud (audience) and, for identity, sub (subject). Together they turn a globally valid token into a token valid for a particular place and person.

The classic failure is a token minted for one service being replayed at another. An internal API that issues tokens for a reporting tool might use the same signing key as the customer-facing API. Without an audience check, a reporting token can call the customer API, because the signature is fine and the expiry has not passed. Adding aud and comparing it with a fixed identifier closes that path.

Issuer is a comparison, not a lookup

iss is a case-sensitive string, usually a URL such as https://auth.example.com. A verifier should compare it with a value it was configured with, or with a fixed list of accepted issuers, and reject anything else before using any claim. The dangerous pattern is to take iss from the token, fetch metadata from that URL, and trust the keys found there. An attacker who can choose iss can point the verifier at their own key set.

Multi-tenant systems sometimes accept many issuers, one per tenant. Even then the mapping from issuer to key set and to tenant must be a server-side table, not a document chosen by the token. The issuer string is an input to a lookup, never the authority for the lookup itself.

Audience can be a string or an array

The specification allows aud to be a single string or an array. A verifier must accept the token when its own identifier appears in the value. If your API is https://api.example.com, a token with "aud": "https://api.example.com" or "aud": ["https://api.example.com", "https://admin.example.com"] is acceptable. A token with only the admin audience is not, even if the signature is valid.

Issuers should be conservative with arrays. Every extra audience is another service that can replay the token, and a token that lists every service has effectively no audience restriction. Use an array only when the same grant genuinely applies to several resource servers, and keep the list short and reviewed.

Subject identifies a principal, not a person's profile

sub is the subject of the token: the principal on whose behalf it was issued. It should be unique within the issuer and stable over time. Provider-specific opaque IDs, such as a UUID or a numeric user ID, are the right choice. An email address is a poor subject because people change addresses, addresses can be reassigned, and the value ends up in logs and support tickets.

When a person signs in with several providers, do not assume their sub values match. Each issuer has its own namespace, so the pair (iss, sub) is the identity. A user with the same email at two providers is not automatically the same account. Linking accounts is a deliberate, auditable action, not a string comparison.

ClaimExampleVerifier actionFailure if skipped
isshttps://auth.example.comExact match against a configured valueToken from another authority accepted
audhttps://api.example.com or an arrayMust contain this service's identifierToken replayed at another service
sub8f14e45f-ceea-467aUse as the principal key, scoped by issuerIdentity confusion across issuers
azpweb-portalCheck the client when the flow requires itToken from another client accepted

A practical validation order

  1. Parse the header and payload without trusting either.
  2. Reject an issuer that is not in the configured set, then choose that issuer's key set.
  3. Reject an algorithm outside the allowlist for that issuer and verify the signature.
  4. Require the audience to contain this service.
  5. Check exp, nbf and iat with a small skew.
  6. Use (iss, sub) as the principal key, and check azp or client_id when the flow requires it.

The order is not sacred, but the checks are. A useful test suite includes a token signed by the right key with the wrong audience, a token with the right audience from the wrong issuer, and a token with both correct but expired. Each must fail for its own reason, and the error should say which check failed without revealing key material.

Common mistakes in the wild

Accepting any audience because the token is only used internally is a mistake that becomes visible the day a second internal service exists. Comparing aud with a prefix rather than the whole string lets https://api.example.com.evil.test pass. Treating the absence of aud as a wildcard is worse: a token with no audience is exactly the token most likely to be replayed.

Another frequent bug is validating iss after using claims from the token. Authorisation decisions based on scope or roles must happen after issuer, audience and signature checks, otherwise a forged token can influence the decision before it is rejected. The safe habit is to build a verified principal object only at the end of validation, and to pass only that object to business logic.

A token valid for someone is not automatically valid for you. Check the audience, every time, on the server.

Sources

Questions

Can aud be an array?

Yes. RFC 7519 allows aud to be a single string or an array of strings. A verifier must accept the token if its own identifier is any member of the array. When issuing, an array is appropriate for a token genuinely intended for several services, not as a shortcut for every service in the company.

Should the verifier trust the iss claim in the token?

It should read iss and compare it with a configured allowlist. Trusting it as a lookup key into an attacker-controlled document is a common mistake. The safest pattern is one verifier instance per issuer with a fixed issuer string and key set.

Is sub the user's email?

Not necessarily, and often not. sub should be a stable, opaque identifier that does not change when the user changes an email or display name. Emails are reassignable and can leak personal data into logs. Use a provider-specific permanent ID, and put the email in a separate claim when you need it.

Decode a token to see iss, aud and sub beside the other claims in the claim table.

Open the verifier

Written against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.

Back to the guides