Secure code review

Auditing OAuth authorisation server grants and token issuance

Delegated identity: person, signature, server arranged to illustrate auditing oauth authorisation server grants and token issuance.

OAuth and OpenID Connect distribute security decisions among clients, providers and resource services. Understanding OAuth authorisation server grants and token issuance helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Authorisation determines which resources and operations an established identity may use. It must be enforced where protected data is read or changed. User interface restrictions, obscure identifiers and documentation can help usability, but they do not replace the service's own permission decision.

Why it matters

Consider a realistic failure: one component trusts a redirect, token or identity assertion without verifying its intended binding to the current flow.

A missing check can expose another account's information or let an ordinary user perform a privileged action. The result should be described by the actual records and operations reached, including whether access crosses a customer or organisational boundary.

A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.

How penetration testers check for it

Review the specific control expectations below against the code, deployment and observable application behaviour.

  • Confirm that the authorisation server validates redirect URIs based on a client-specific allowlist of pre-registered URIs using exact string comparison.
  • Verify that, if the authorisation server returns the authorisation code in the authorisation response, it can be used only once for a token request. For the second valid request with an authorisation code that has already been used to issue an access token, the authorisation server must reject a token request and revoke any issued tokens related to the authorisation code.
  • Confirm that the authorisation code is short-lived. The maximum lifetime can be up to 10 minutes for L1 and L2 applications and up to 1 minute for L3 applications.
  • Confirm that for a given client, the authorisation server only allows the usage of grants that this client needs to use. Note that the grants 'token' (Implicit flow) and 'password' (Resource Owner Password Credentials flow) must no longer be used.
  • Confirm that the authorisation server mitigates refresh token replay attacks for public clients, preferably using sender-constrained refresh tokens, i.e., Demonstrating Proof of Possession (DPoP) or Certificate-Bound Access Tokens using mutual TLS (mTLS). For L1 and L2 applications, refresh token rotation may be used. If refresh token rotation is used, the authorisation server must invalidate the refresh token after usage, and revoke all refresh tokens for that authorisation if an already used and invalidated refresh token is provided.
  • Verify that, if the code grant is used, the authorisation server mitigates authorisation code interception attacks by requiring proof key for code exchange (PKCE). For authorisation requests, the authorisation server must require a valid 'code_challenge' value and must not accept a 'code_challenge_method' value of 'plain'. For a token request, it must require validation of the 'code_verifier' parameter.
  • Confirm that if the authorisation server supports unauthenticated dynamic client registration, it mitigates the risk of malicious client applications. It must validate client metadata such as any registered URIs, ensure the user's consent, and warn the user before processing an authorisation request with an untrusted client application.
  • Confirm that refresh tokens have an absolute expiration, including if sliding refresh token expiration is applied.
  • Confirm that refresh tokens and reference access tokens can be revoked by an authorised user using the authorisation server user interface, to mitigate the risk of malicious clients or stolen tokens.
  • Confirm that confidential client is authenticated for client-to-authorised server backchannel requests such as token requests, pushed authorisation requests (PAR), and token revocation requests.
  • Confirm that the authorisation server configuration only assigns the required scopes to the OAuth client.
  • Confirm that for a given client, the authorisation server only allows the 'response_mode' value that this client needs to use. For example, by having the authorisation server validate this value against the expected values or by using pushed authorisation request (PAR) or JWT-secured Authorisation Request (JAR).
  • Confirm that grant type 'code' is always used together with pushed authorisation requests (PAR).
  • Confirm that the authorisation server issues only sender-constrained (Proof-of-Possession) access tokens, either with certificate-bound access tokens using mutual TLS (mTLS) or DPoP-bound access tokens (Demonstration of Proof of Possession).
  • Verify that, for a server-side client (which is not executed on the end-user device), the authorisation server ensures that the 'authorisation_details' parameter value is from the client backend and that the user has not tampered with it. For example, by requiring the usage of pushed authorisation request (PAR) or JWT-secured Authorisation Request (JAR).
  • Confirm that the client is confidential and the authorisation server requires the use of strong client authentication methods (based on public-key cryptography and resistant to replay attacks), such as mutual TLS ('tls_client_auth', 'self_signed_tls_client_auth') or private key JWT ('private_key_jwt').
  • Test nested resources, background processing and state changes.
  • Confirm rejection as well as the legitimate successful journey.

How to fix it

Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.

  • Define explicit access rules and default-deny behaviour.
  • Bind resource selection to trusted ownership and tenant context.
  • Enforce permission checks at each protected operation.
  • Maintain regression cases for unauthorised users and changed permissions.

A successful response alone does not prove unauthorised access. Establish whose resource was affected and what the caller was legitimately entitled to do.

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.

Read about our methodology or contact pentested.com to discuss the security of your application code.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo