OAuth access token audience and scope validation in APIs
An access token issued for one resource or scope must not automatically authorise another. Understanding OAuth access token audience and scope validation in APIs helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Session and token controls preserve an authentication decision over time. They need a defined scope, lifetime and invalidation policy. A token should be accepted because a trusted service has verified the relevant properties, not simply because its structure looks familiar.
Therefore, the requirements listed here are OAuth or OIDC specific and should be performed after token validation and before performing authorisation based on information from the token.
Why it matters
Consider a realistic failure: a token for a reporting service is accepted by a payment API.
A reusable credential can let someone continue acting as an account after the intended access should have ended. Long-lived access, excessive token contents and inconsistent revocation can increase the exposure beyond the initial event.
An API review follows the server-side behaviour behind the interface. Direct requests, alternate methods and background operations can reveal boundaries that the normal frontend journey does not exercise.
How penetration testers check for it
Validate issuer, audience, expiry and required operation scopes at the resource server.
- Confirm that the resource server only accepts access tokens that are intended for use with that service (audience). The audience may be included in a structured access token, or it can be checked using the token introspection endpoint.
- Confirm that the resource server enforces authorisation decisions based on claims from the access token that define delegated authorisation. If claims such as 'sub', 'scope', and 'authorisation_details' are present, they must be part of the decision.
- Confirm that if an access control decision requires identifying a unique user from an access token (JWT or related token introspection response), the resource server identifies the user from claims that cannot be reassigned to other users. Typically, it means using a combination of 'iss' and 'sub' claims.
- Verify that, if the resource server requires specific authentication strength, methods, or recentness, it verifies that the presented access token satisfies these constraints. For example, if present, using the OIDC 'acr', 'amr' and 'auth_time' claims respectively.
- Confirm that the resource server prevents the use of stolen access tokens or replay of access tokens (from unauthorised parties) by requiring sender-constrained access tokens, either Mutual TLS for OAuth 2 or OAuth 2 Demonstration of Proof of Possession (DPoP).
- Test logout, permission changes and credential replacement.
- Inspect replay and concurrent use according to the documented design.
How to fix it
Bind trusted tokens to their intended resource and apply operation-specific authorisation.
- Use appropriately scoped credentials with bounded lifetimes.
- Validate trusted issuance and relevant claims consistently.
- Rotate and revoke according to the session model.
- Keep credentials out of unnecessary URLs, logs and persistent copies.
Some designs intentionally use short-lived credentials without immediate global revocation. Assess the complete lifetime and access model before calling that design a failure.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Reviewing OAuth resource server token acceptance
- JWT signature and algorithm validation in API gateways
- API key scope, leakage and revocation
Read about our methodology or contact pentested.com to discuss your APIs and integrations.