Secure development

Implementing OAuth flows with safe redirects and token boundaries

Delegated identity: person, signature, server arranged to illustrate implementing oauth flows with safe redirects and token boundaries.

Implementing OAuth flows with safe redirects and token boundaries connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding OAuth flows with safe redirects and token boundaries 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.

OAuth 2.0 public clients utilizing the Authorisation Code Grant are susceptible to the authorisation code interception attack. Proof Key for Code Exchange (PKCE, pronounced "pixy") is the technique used to mitigate against the threat of authorisation code interception attack.

Originally, PKCE is intended to be used solely focused on securing native apps, but then it became a deployed OAuth feature. It does not only protect against authorisation code injection attacks but also protects authorisation codes created for public clients as PKCE ensures that the attacker cannot redeem a stolen authorisation code at the token endpoint of the authorisation server without knowledge of the code_verifier.

Why it matters

Consider a realistic failure: an OAuth redirect or token exchange is not correctly bound to the client and flow that initiated it.

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.

Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.

How penetration testers check for it

Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.

  • Review token creation, transport, storage and acceptance.
  • Check issuer, intended recipient, lifetime and required claims.
  • Test logout, permission changes and credential replacement.
  • Inspect replay and concurrent use according to the documented design.

How to fix it

Use the appropriate maintained mechanisms and verify the result in the actual production configuration.

  • Resource Owner (RO): Refers to an entity capable of granting access to a protected resource. When the resource owner is a person, it is referred to as an end user. It can also be an organisation or system.
  • Clients and Authorisation Server must not expose URLs that forward the user's browser to arbitrary URIs obtained from a query parameter ("open redirectors") which can enable exfiltration of authorisation codes and access tokens.
  • Clients have ensured that the Authorisation Server supports PKCE may rely on the CSRF protection provided by PKCE. In OpenID Connect flows, the "nonce" parameter provides CSRF protection. Otherwise, one-time user CSRF tokens carried in the "state" parameter that are securely bound to the user agent must be used for CSRF protection.
  • When an OAuth Client can interact with more than one Authorisation Server, Clients should use the issuer "iss" parameter as a countermeasure, or based on an "iss" value in the authorisation response (such as the "iss" Claim in the ID Token in OpenID).
  • 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.

Read about our methodology or contact pentested.com to discuss secure development and code review.

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