Skip to content
OAuth / SSO Write-up Advanced

The OAuth Code Apigee Let Me Choose

An Apigee OAuthV2 policy that was not configured to import an external authorization code still read a request form field named external_auth_code and used its value as the issued authorization code. An attacker could therefore choose the code value, and when a victim completed the authorization request, the victim's authorization was stored behind the attacker-known code, allowing the attacker to exchange it for tokens tied to the victim.

Nikita Markevich Follow

Published on bugs.exposed

Comment

Nikita Markevich, on bugs.exposed

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

Context

Apigee is an API gateway. A customer exposes an HTTP endpoint as an API proxy and adds policies that run as the request passes through it. One of those policies, OAuthV2, lets the proxy act as an OAuth authorization server: depending on its configured operation it can create an authorization code, exchange that code for tokens, refresh a token, or verify a bearer token before allowing an API call through.

In the ordinary authorization-code flow, Apigee creates a random code and stores the OAuth data associated with it. The browser carries that opaque value back to the client, and the client later presents it to the token endpoint. Apigee uses the code to recover the stored authorization and issue tokens. The code is therefore more than a random receipt: it is the identifier that joins the authorization performed in the browser to the later token exchange. An authorization server is supposed to choose its authorization codes. A client may carry a code through a redirect and exchange it later, but it does not get to decide what that code is.

Apigee also supports a less common arrangement: it can import codes and tokens created by another authorization system. Rather than replace that system, an Apigee proxy can call it, validate its response, extract the returned value into a flow variable, and ask OAuthV2 to store that value with Apigee's token metadata. The relevant policy element names the variable explicitly:

XML
<ExternalAuthorizationCode>external.idp.authorization_code</ExternalAuthorizationCode>

That explicit reference is the source-selection decision. A proxy author may point it at a value prepared by earlier policy logic, or even deliberately at a request variable, but the choice belongs in the policy configuration. Without the element, no caller-controlled form field has been selected as the external code source.

There is another setting with a confusingly broad name: ExternalAuthorization. It is not the master switch for this whole feature. It decides whether the policy performs its normal client-credential validation or relies on an external validation result prepared by the proxy. Even in the external mode, Apigee still requires a known, valid client ID. The elements ExternalAuthorizationCode, ExternalAccessToken, and ExternalRefreshToken separately choose the source of each imported artifact.

Setup

The research targeted Google Cloud Apigee, runtime 1-17-0-apigee-6. The test policy left ExternalAuthorization false, so Apigee still checked client credentials. More importantly, it did not contain any of the three artifact elements. There was no configured flow variable from which an external code or token could come. This should have been a completely ordinary, Apigee-generated OAuth flow.

For the end-to-end tests the researcher built a small authorization endpoint, a token endpoint, and an identity endpoint. The identity endpoint verified the resulting access token and returned the test end_user stored behind it. That gave a direct way to distinguish "Apigee echoed my string" from "Apigee accepted my string as an OAuth credential." A victim test account and an attacker test account were used, and a confidential web application with a backend for frontend (BFF) was built for the harder variant.

The work was reported on 9 April 2026. The report lists the issue as patched and the bounty as not awarded.

Finding it

The researcher was tracing the decompiled OAuthV2 implementation and noticed the name external_auth_code surviving even when ExternalAuthorizationCode was absent. Before following it through another stack of methods, the laziest possible test was tried: send that name as a normal form parameter with a value that would be impossible to mistake for a generated code.

On runtime 1-17-0-apigee-6, external_auth_code=attacker-chosen-code was added to an otherwise valid authorization request. The policy was not configured to import a code. The expectation was that the extra field would be ignored, or at least rejected.

The redirect came back with the supplied value:

HTTP
Location: https://client.example/callback?code=attacker-chosen-code&state=...

Apigee had processed a valid authorization request, but the identifier leaving the authorization endpoint was one supplied on the way in. The result alone did not tell whether this was a documented default, a leftover compatibility path, or a value that would disappear before persistence. The concrete question was: how did a public form field reach a slot intended for a flow variable selected by the proxy author?

Exploitation

Step 1: the fallback key is external_auth_code

The chain crossed three layers: policy initialization, request handling, and OAuth persistence. The constant is defined in OAuthStepConstants.java:

Java
    public static final String CLIENT_SECRET = "client_secret";
    public static final String USERNAME = "username";
    public static final String VERIFY_API_KEY_PREFIX = "verifyapikey.";
    public static final String GET_APIPRODUCT_PREFIX = "getapiproduct.";
    public static final String EXTERNAL_ACCESS_TOKEN = "external_access_token";
    public static final String EXTERNAL_REFRESH_TOKEN = "external_refresh_token";
    public static final String EXTERNAL_AUTH_CODE = "external_auth_code";
    public static final String STORE_TOKEN = "store_token";
    public static final String ACCESS_TOKEN_TYPE = "accesstoken";
    public static final String REFRESH_TOKEN_TYPE = "refreshtoken";
    public static final String DEVELOPER_ID = "developer.id";
    public static final String DEVELOPER_APP_ID = "developer.app.id";

Line 33 shows that EXTERNAL_AUTH_CODE is the literal string external_auth_code.

Step 2: the authorization step creates the resolver

In GenerateAuthorizationCodeExecution.java:41, the call site supplies both the optional policy element and the fixed external_auth_code fallback name:

Java
        this.externalAuthorizationCode = buildRef(stepDefinition.getExternalAuthorizationCode(), OAuthStepConstants.EXTERNAL_AUTH_CODE);

Step 3: an absent source selects the map lookup

AbstractOAuthStepExecution.buildRef decides what an absent element means:

Java
    public static RefOrValue buildRef(String variable, String constantName) {
        if (StringUtils.isNotEmpty(variable)) {
            return RefOrValue.forReference(variable);
        }
        return RefOrValue.forKeyFromMap((String) Preconditions.checkNotNull(constantName));
    }

Line 710: a configured policy element becomes an explicit flow-variable reference. Line 713: when that element is absent, buildRef passes the fallback name to forKeyFromMap.

Step 4: the resolver reads the named map entry

RefOrValue.forKeyFromMap (line 79) returns map.get(key); its caller decides which map supplies the value:

Java
    public static RefOrValue forKeyFromMap(String key) {
        ResolutionFunction<MessageContext, Map<String, String>> resolverFunction = (messageContext, map) -> {
            return (String) map.get(key);
        };
        return new RefOrValue(false, key, resolverFunction);
    }

Step 5: the request form becomes the map

In GenerateAuthorizationCodeExecution.execute (line 50), formParameters comes directly from the incoming authorization request:

Java
        RequestParameters requestParameters = fetchQueryParamsAndFormParams(messageContext);
        Map<String, String> queryParameters = requestParameters.getQueryParameters();
        Map<String, String> formParameters = requestParameters.getFormParameters();

Step 6: the external-code resolver reads that form

Line 58: the resolver keyed by external_auth_code now runs against the request-controlled form map:

Java
        clientContext.setExternalAuthorizationCode(this.externalAuthorizationCode.resolve(messageContext, formParameters));

The execution path crossed the trust boundary. GenerateAuthorizationCodeExecution resolved that key against the incoming form, so a source that the proxy author had never selected became request-controlled input. Both the configured flow variable and the fallback form value then arrived in the same externalAuthorizationCode field.

Step 7: a supplied code replaces random generation

The persistence layer had one last chance to distinguish them. In OAuth2RuntimeServiceImpl.createAuthorizationCode (lines 229 to 232) it checked only whether that field was null:

Java
        if (authorizationCode.getExternalAuthorizationCode() != null) {
            authorizationCode.setCode(authorizationCode.getExternalAuthorizationCode());
        } else {
            generateAuthorizationCodeValue(authorizationCode, keyStatus.getAppCredential().getOrganizationName());
        }

A supplied value became the stored authorization code. Random generation ran only when the external field was null. The form value was already labelled "external," so Apigee stored it unchanged and never called the random generator.

Step 8: the token paths build the same fallbacks

GenerateAccessTokenExecution built the same fallback resolvers in its constructor (lines 48 and 49):

Java
        this.accessTokenRef = buildRef(stepDefinition.getExternalAccessToken(), OAuthStepConstants.EXTERNAL_ACCESS_TOKEN);
        this.refreshTokenRef = buildRef(stepDefinition.getExternalRefreshToken(), OAuthStepConstants.EXTERNAL_REFRESH_TOKEN);

Step 9: the flag does not guard either resolver

In GenerateAccessTokenExecution.execute (lines 72 to 74), ExternalAuthorization is recorded separately from artifact source selection, and both resolvers run against formParameters:

Java
        clientContext.setExternalAuthorization(((OAuthV2StepDefinition) this.stepDefinition).isExternalAuthorization());
        clientContext.setAccessToken(this.accessTokenRef.resolve(messageContext, formParameters));
        clientContext.setExternalRefreshToken(this.refreshTokenRef.resolve(messageContext, formParameters));

The fixed keys changed to external_access_token and external_refresh_token; the trust decision did not.

Step 10: the chosen code carried the victim's identity

For the first end-to-end test, an authorization code was chosen, then the victim test account submitted the authorization request while signed in. Apigee returned that same code and stored the victim's authorization behind it. Exchanging the known code produced an access token whose end_user was the victim.

The simplest proof used a client where the complete OAuth flow was controlled. A real confidential web application raised a harder objection: its client secret stays on the server, and PKCE ties the code exchange to a verifier that never appears in the browser. Knowing the code should not give an attacker either value.

Step 11: the confidential-client chain

The application used a backend for frontend. A normal login was begun in the attacker's browser. The BFF created the transaction, stored the state and PKCE verifier server-side, set a transaction cookie, and returned an authorization request containing the matching state and code challenge. At this point the attacker merely owned a valid login attempt.

Instead of submitting that request, its public parameters were placed into a cross-origin form for the victim. The attacker's state and PKCE code challenge were preserved, and the chosen external_auth_code was added. The victim submitted the form while authenticated to the test SSO system.

Apigee then assembled a code record from three different owners: the attacker had chosen the code, the victim supplied the authenticated identity, and the code challenge belonged to the attacker's BFF transaction.

The first callback reached the BFF through the victim's browser. The BFF rejected it because that browser did not have the attacker's transaction cookie. That rejection showed the application's state handling was doing its job, but it did not invalidate the authorization code stored by Apigee.

The attacker already knew that code and still owned the original browser transaction. Opening the callback there gave the BFF the expected cookie and state. The BFF supplied its own client secret and the PKCE verifier it had stored at the beginning. The verifier matched the challenge attached to the chosen code, so Apigee returned tokens for the victim identity and the BFF created the attacker's application session as the victim.

Every control around the confidential client behaved as designed. The victim's callback was rejected. The client secret never entered either browser. State matched only in the attacker-owned transaction, and PKCE allowed only the party holding its verifier to redeem the code. The attacker was that party. The broken assumption sat one step earlier: Apigee had allowed the request to choose the identifier that joined the victim's authorization to the attacker's transaction.

The attack still required a usable authorization flow and a victim who submitted the authorization request while signed in. Supplying the form parameter alone did not authenticate anyone. What it supplied was the join key; the normal login and code exchange supplied everything around it.

Step 12: access-token fixation

In an implicit flow, where the authorization endpoint returns an access token directly, external_access_token was supplied before the victim authorized. Apigee returned that exact opaque value, and presenting it to the identity endpoint resolved to the victim test account. This was the same shape as the code result: choose an identifier first, let Apigee attach the victim later.

Step 13: access-token rebinding

The test began with a known access-token value associated with the victim test account. Supplying that value during an authorization-code exchange under the attacker test account caused the identity endpoint to resolve the same string to the attacker afterwards. No new predictable token was needed; the existing identifier acquired a different owner.

Step 14: refresh-token rebinding

The before-and-after check was repeated with external_refresh_token. A refresh token that initially represented the victim became attached to attacker context, and refreshing it later produced an attacker-context access token.

Those last two results are why the researcher distinguishes fixation from rebinding. Fixation chooses the identifier before Apigee stores the identity. Rebinding starts with an identifier that already exists and changes the identity behind it. The unsafe input source was the same, but the OAuth operation determined what persistence did with the value.

The rebinding tests included one unglamorous complication: cache. Token metadata could remain on an Apigee runtime node after the backing record changed. The tests either retried against another node or waited through the documented 180-second cache period before trusting the identity result.

Static inspection showed another refresh-token route during an authorization-code exchange. It was not included in the live proof because it required influence over the exchange request itself. It remains a code-supported variant, separate from the three behaviours that were reproduced.

Root cause

The line that matters is not in a random-number generator or an OAuth cryptographic check. It is the generic fallback in buildRef(). When the proxy author named a flow variable, the helper read that explicit source. When the author named nothing, the helper did not stop. It looked in the caller's form under a conventional key.

That small default erased the distinction between an artifact imported deliberately by proxy logic and one volunteered by the HTTP client. Everything after it behaved consistently: the OAuth context carried a non-null external value, persistence honoured it, state matched, and PKCE verified the attacker's transaction.

None of the controls that usually attract attention had to be broken. The code was random when Apigee generated it. The client secret stayed secret. PKCE verified the correct verifier. The interesting question was earlier and much less glamorous: when a security-sensitive setting is absent, does the operation stop, or does some fallback quietly choose a new source?

Impact

An attacker who can get a victim to submit an authorization request while signed in can choose the authorization code, access token, or refresh token identifier that Apigee stores against the victim's authorization. With a confidential client using PKCE, the attacker can still redeem the code in their own browser transaction and obtain an application session as the victim, because the attacker controls the verifier and state that match the chosen code. The same input source allows fixation of access and refresh tokens, and rebinding of existing tokens to a different identity.

Supplying the form parameter alone does not authenticate anyone; it supplies the join key, and the normal login and code exchange supply everything around it. The rebinding results can be masked by the runtime cache, so identity checks may need a retry on another node or a wait through the documented 180-second cache period.

Fix

The report lists the issue as patched but does not describe the change. The behaviour at the centre of the finding is the fallback in buildRef(): when no external artifact element is configured, the resolver falls back to a request form key. The operation should either stop or use only an explicitly configured source, so that "not configured" cannot become a caller-controlled input.

Variants to test

  1. Other OAuthV2 artifact elements. Send external_access_token and external_refresh_token as form parameters on proxies that do not configure ExternalAccessToken or ExternalRefreshToken. A positive result is the redirect or token response returning the exact supplied value, and the identity endpoint resolving it to the victim account.
  2. Implicit flow fixation. Supply external_access_token before the victim authorizes in an implicit flow. A positive result is the authorization endpoint returning that exact opaque value and the identity endpoint resolving it to the victim.
  3. Rebinding an existing token. Take a known access or refresh token belonging to one account, supply it during an exchange under another account, then check the identity endpoint. A positive result is the same string resolving to the new owner after the cache period.
  4. Confidential client with PKCE. Start a login in the attacker's browser, capture the state and code challenge, place them with a chosen external_auth_code into a cross-origin form for the victim, then redeem the known code in the attacker's original transaction. A positive result is tokens for the victim identity issued to the attacker's BFF session.
  5. Refresh-token route during code exchange. Inspect the exchange path for a refresh-token resolver that runs against the exchange request. A positive result is a refresh token supplied in the exchange request being stored against the resulting authorization.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 26 min read.

What happened, in plain words

Imagine a hotel. When you check in, the receptionist gives you a key card with a random number on it. That number is not something you pick; the hotel picks it, writes it down, and later uses it to look up which room is yours and what you are allowed to do. If guests could choose their own key card numbers, a guest could pick a number that the hotel would later associate with someone else's room.

That is roughly what this report is about, but for a piece of software called Apigee, made by Google. Apigee is an API gateway: a piece of software that sits in front of a company's online services and decides who is allowed to talk to them. One of the jobs it can do is act as an OAuth authorization server, which is the part of a login system that hands out the short-lived passes (called tokens) that prove who you are.

In a normal OAuth login, the server is supposed to invent the authorization code itself, at random. The browser carries that code back to the application, and the application swaps it for tokens. The code is the thread that ties the login you just did in your browser to the later exchange. If an attacker can choose that thread, they can tie their own transaction to your identity.

The researcher found that Apigee, when a particular optional setting was left out of a configuration, quietly fell back to reading the code from a normal form field sent by the browser. That meant anyone could send external_auth_code=attacker-chosen-code and Apigee would use that value as the authorization code. The same fallback existed for access tokens and refresh tokens. The researcher then showed that a victim who simply submitted a login form while signed in would have their identity attached to the attacker's chosen code, and the attacker could redeem it for a session as the victim, even against a well-built application that used a client secret and PKCE (two standard protections).

The issue was reported on 9 April 2026. The report lists it as patched and the bounty as not awarded.

The pieces you need to know

Before the details, a few everyday ideas. None of them require any security background.

  • An API is a way for one program to talk to another over the internet. When a weather app on your phone shows the forecast, it is asking a weather company's API for the data. An API is like a service counter: you ask for something in a fixed way, and you get an answer back.
  • An API gateway is the front desk in front of that counter. Every request passes through it first, and it can check who you are, apply rules, and only then let the request through. Apigee is one of these.
  • A proxy (here, an API proxy) is the configuration inside the gateway that describes one particular service: which address it listens on, and which rules (called policies) run as each request passes through.
  • A policy is a small rule that runs during a request. One policy might check a password; another might add a header; another, called OAuthV2, handles OAuth login logic.
  • OAuth is the standard way apps let you log in with another service without handing over your password. When a website shows a "Sign in with Google" button, OAuth is usually what happens behind it.
  • An authorization code is a short, random string that the login server gives to the browser after you log in. The browser passes it to the application, and the application swaps it for tokens. Think of it as a claim ticket: the cloakroom gives you a ticket, and later you hand the ticket back to collect your coat. The cloakroom chooses the ticket number, not you.
  • A token (access token or refresh token) is the pass that proves who you are on later requests. An access token is short-lived and used to call APIs. A refresh token is longer-lived and used to get a new access token when the old one expires.
  • A cookie is a small piece of data a website stores in your browser so it can recognise you on the next request. It is how a site remembers that you are logged in between page loads.
  • PKCE (pronounced "pixy") is an extra protection for OAuth. The application invents a secret random string (the verifier), sends a scrambled version of it (the challenge) with the login request, and later proves it knows the original when it exchanges the code. Only the party that holds the verifier can redeem the code. It is like a cloakroom that asks you to prove you know a password you set when you dropped the coat off.
  • A client secret is a password that a server-side application uses to prove to the login server that it really is that application. It never goes into the browser.
  • A BFF (backend for frontend) is a small server that sits between the browser and the login system, holding secrets and session state on the server side so the browser never sees them.
  • State is a random value the application sends with a login request and checks when the answer comes back, to make sure the answer belongs to a login the application itself started. It defends against an attacker slipping their own login into your browser.
  • Fixation and rebinding are the two shapes of this bug. Fixation means the attacker picks the identifier before the server stores an identity behind it. Rebinding means the identifier already exists and the attacker changes which identity it points to.
  • A flow variable is a named slot inside Apigee that holds a value during a request, such as a header, a form field, or something an earlier policy computed. Policies can read from and write to these slots.

How Apigee normally chooses the code

Apigee lets a customer expose an HTTP endpoint as an API proxy, then add policies that run as the request passes through. One of those policies, OAuthV2, lets the proxy act as an OAuth authorization server. Depending on how it is configured, it can create an authorization code, exchange that code for tokens, refresh a token, or verify a bearer token before allowing an API call through.

In the ordinary authorization-code flow, Apigee creates a random code and stores the OAuth data associated with it. The browser carries that opaque value back to the client, and the client later presents it to the token endpoint. Apigee uses the code to recover the stored authorization and issue tokens. The code is therefore more than a random receipt: it is the identifier that joins the authorization performed in the browser to the later token exchange.

An authorization server is supposed to choose its authorization codes. A client may carry a code through a redirect and exchange it later, but it does not get to decide what that code is. That rule is so basic that it usually disappears into the wallpaper of an OAuth review.

Apigee also supports a less common arrangement: it can import codes and tokens created by another authorization system. Rather than replace that system, an Apigee proxy can call it, validate its response, extract the returned value into a flow variable, and ask OAuthV2 to store that value with Apigee's token metadata. The relevant policy element names the variable explicitly:

XML
<ExternalAuthorizationCode>external.idp.authorization_code</ExternalAuthorizationCode>

This is a piece of Apigee configuration. The tag name ExternalAuthorizationCode tells the policy that an outside system will supply the code. The text inside the tag, external.idp.authorization_code, is the name of the flow variable where that outside value will be found. The proxy author is making an explicit choice: "take the code from this named slot." That explicit reference is the source-selection decision. A proxy author may point it at a value prepared by earlier policy logic, or even deliberately at a request variable, but the choice belongs in the policy configuration. Without the element, no caller-controlled form field has been selected as the external code source.

There is another setting with a confusingly broad name: ExternalAuthorization. It is not the master switch for this whole feature. It decides whether the policy performs its normal client-credential validation or relies on an external validation result prepared by the proxy. Even in the external mode, Apigee still requires a known, valid client ID. The elements ExternalAuthorizationCode, ExternalAccessToken, and ExternalRefreshToken separately choose the source of each imported artifact. In plain terms: ExternalAuthorization is about who checked the client's credentials, while the three artifact elements are about where the code or token value comes from. They are different questions, and the researcher initially misread the first as covering the second.

The setup for the test

The research targeted Google Cloud Apigee, runtime 1-17-0-apigee-6. The test policy left ExternalAuthorization false, so Apigee still checked client credentials. More importantly, it did not contain any of the three artifact elements. There was no configured flow variable from which an external code or token could come. This should have been a completely ordinary, Apigee-generated OAuth flow.

For the end-to-end tests the researcher built a small authorization endpoint, a token endpoint, and an identity endpoint. The identity endpoint verified the resulting access token and returned the test end_user stored behind it. That gave a direct way to distinguish "Apigee echoed my string" from "Apigee accepted my string as an OAuth credential." In other words, if Apigee merely repeated the attacker's string back, that would be a curiosity; if the identity endpoint then said "this token belongs to the victim test account," that would be a real security problem. A victim test account and an attacker test account were used, and a confidential web application with a backend for frontend (BFF) was built for the harder variant.

The work was reported on 9 April 2026.

Finding it

The researcher was tracing the decompiled OAuthV2 implementation and noticed the name external_auth_code surviving even when ExternalAuthorizationCode was absent. Decompiling means turning the compiled program back into readable source code so you can follow what it does. Before following it through another stack of methods, the laziest possible test was tried: send that name as a normal form parameter with a value that would be impossible to mistake for a generated code.

On runtime 1-17-0-apigee-6, external_auth_code=attacker-chosen-code was added to an otherwise valid authorization request. The policy was not configured to import a code. The expectation was that the extra field would be ignored, or at least rejected.

The redirect came back with the supplied value:

HTTP
Location: https://client.example/callback?code=attacker-chosen-code&state=...

This is an HTTP response header. Location tells the browser where to go next, which in an OAuth login is the application's callback address. The code= part is the authorization code, and here it is exactly the string the researcher sent in. The state=... part is the application's own random value, echoed back so the application can check it. Apigee had processed a valid authorization request, but the identifier leaving the authorization endpoint was one supplied on the way in.

The result alone did not tell whether this was a documented default, a leftover compatibility path, or a value that would disappear before persistence. Persistence here means the moment Apigee writes the code and its associated data into its storage. The concrete question was: how did a public form field reach a slot intended for a flow variable selected by the proxy author?

Following the value through the code

The chain crossed three layers: policy initialization, request handling, and OAuth persistence. Initialization is where Apigee reads the policy configuration and prepares its objects. Request handling is where it reads the incoming request. Persistence is where it stores the result. The researcher walked through the decompiled files step by step, and the next sections follow the same order.

Step 1: the fallback key is external_auth_code

The constant is defined in OAuthStepConstants.java:

Java
    public static final String CLIENT_SECRET = "client_secret";
    public static final String USERNAME = "username";
    public static final String VERIFY_API_KEY_PREFIX = "verifyapikey.";
    public static final String GET_APIPRODUCT_PREFIX = "getapiproduct.";
    public static final String EXTERNAL_ACCESS_TOKEN = "external_access_token";
    public static final String EXTERNAL_REFRESH_TOKEN = "external_refresh_token";
    public static final String EXTERNAL_AUTH_CODE = "external_auth_code";
    public static final String STORE_TOKEN = "store_token";
    public static final String ACCESS_TOKEN_TYPE = "accesstoken";
    public static final String REFRESH_TOKEN_TYPE = "refreshtoken";
    public static final String DEVELOPER_ID = "developer.id";
    public static final String DEVELOPER_APP_ID = "developer.app.id";

This is a list of named constants: fixed strings that the rest of the program refers to by name. public static final String means "a string that never changes and can be used anywhere in the code." Line 33 shows that EXTERNAL_AUTH_CODE is the literal string external_auth_code. The other lines are neighbours in the same list: client_secret, username, external_access_token, external_refresh_token, and so on. The important one for now is line 33, because it is the name that will later be looked up in the request.

Step 2: the authorization step creates the resolver

In GenerateAuthorizationCodeExecution.java:41, the call site supplies both the optional policy element and the fixed external_auth_code fallback name:

Java
        this.externalAuthorizationCode = buildRef(stepDefinition.getExternalAuthorizationCode(), OAuthStepConstants.EXTERNAL_AUTH_CODE);

A resolver is a small object whose job is to produce a value when asked. Here, buildRef is a helper that builds one. It receives two things: stepDefinition.getExternalAuthorizationCode(), which is whatever the proxy author wrote in the policy (possibly nothing), and OAuthStepConstants.EXTERNAL_AUTH_CODE, which is the fixed string external_auth_code from step 1. The result is stored in this.externalAuthorizationCode. The question the rest of the code answers is: what does buildRef do with those two inputs?

Step 3: an absent source selects the map lookup

AbstractOAuthStepExecution.buildRef decides what an absent element means:

Java
    public static RefOrValue buildRef(String variable, String constantName) {
        if (StringUtils.isNotEmpty(variable)) {
            return RefOrValue.forReference(variable);
        }
        return RefOrValue.forKeyFromMap((String) Preconditions.checkNotNull(constantName));
    }

Line by line:

  1. public static RefOrValue buildRef(String variable, String constantName) declares the helper. It takes the configured variable name and a fallback constant name, and returns a RefOrValue, which is either a reference to a named flow variable or a lookup in a map.
  2. if (StringUtils.isNotEmpty(variable)) asks: did the proxy author actually name something?
  3. return RefOrValue.forReference(variable); If yes, the resolver will read that named flow variable. This is the intended path.
  4. return RefOrValue.forKeyFromMap((String) Preconditions.checkNotNull(constantName)); If no, the helper does not stop. It builds a resolver that looks up the fallback name in a map. Preconditions.checkNotNull just makes sure the fallback name is not null.

Line 710 in the original tour corresponds to the configured case: a configured policy element becomes an explicit flow-variable reference. Line 713 corresponds to the absent case: when that element is absent, buildRef passes the fallback name to forKeyFromMap. This is the heart of the bug: "not configured" was treated as "look in the request under a conventional name" rather than "there is no external source."

Step 4: the resolver reads the named map entry

RefOrValue.forKeyFromMap (line 79) returns map.get(key); its caller decides which map supplies the value:

Java
    public static RefOrValue forKeyFromMap(String key) {
        ResolutionFunction<MessageContext, Map<String, String>> resolverFunction = (messageContext, map) -> {
            return (String) map.get(key);
        };
        return new RefOrValue(false, key, resolverFunction);
    }

Line by line:

  1. public static RefOrValue forKeyFromMap(String key) declares a factory that builds a resolver for a given key.
  2. ResolutionFunction<MessageContext, Map<String, String>> resolverFunction = (messageContext, map) -> { defines the function that will run later. It receives the current message context and a map of strings, and returns a string.
  3. return (String) map.get(key); is the actual lookup: give me the value stored under key in this map. If the key is not there, this returns null.
  4. return new RefOrValue(false, key, resolverFunction); wraps that function in a RefOrValue and returns it. The false marks it as a map lookup rather than a named reference.

The key point: this resolver does not decide which map to use. Its caller does. That is why the next step matters so much.

Step 5: the request form becomes the map

In GenerateAuthorizationCodeExecution.execute (line 50), formParameters comes directly from the incoming authorization request:

Java
        RequestParameters requestParameters = fetchQueryParamsAndFormParams(messageContext);
        Map<String, String> queryParameters = requestParameters.getQueryParameters();
        Map<String, String> formParameters = requestParameters.getFormParameters();

Line by line:

  1. RequestParameters requestParameters = fetchQueryParamsAndFormParams(messageContext); collects the parameters from the incoming request. messageContext is Apigee's object representing the current request and its variables.
  2. Map<String, String> queryParameters = requestParameters.getQueryParameters(); pulls out the parameters that came in the URL after the ?.
  3. Map<String, String> formParameters = requestParameters.getFormParameters(); pulls out the parameters that came in the request body as a form submission.

A map here is just a lookup table: names on one side, values on the other. formParameters is a table built from whatever the browser sent in the form. If the browser sent external_auth_code=attacker-chosen-code, that pair is in this table.

Step 6: the external-code resolver reads that form

Line 58: the resolver keyed by external_auth_code now runs against the request-controlled form map:

Java
        clientContext.setExternalAuthorizationCode(this.externalAuthorizationCode.resolve(messageContext, formParameters));

Line by line:

  1. this.externalAuthorizationCode.resolve(messageContext, formParameters) asks the resolver from step 2 to produce a value, passing the request context and the form map from step 5.
  2. Because the policy had no ExternalAuthorizationCode element, the resolver is the map lookup from step 4, keyed by external_auth_code.
  3. So it returns formParameters.get("external_auth_code"), which is whatever the browser sent.
  4. clientContext.setExternalAuthorizationCode(...) stores that value in the OAuth client context, the object that carries data through the rest of the flow.

The execution path crossed the trust boundary. GenerateAuthorizationCodeExecution resolved that key against the incoming form, so a source that the proxy author had never selected became request-controlled input. Both the configured flow variable and the fallback form value then arrived in the same externalAuthorizationCode field. The rest of the code could no longer tell which one it was looking at.

Step 7: a supplied code replaces random generation

The persistence layer had one last chance to distinguish them. In OAuth2RuntimeServiceImpl.createAuthorizationCode (lines 229 to 232) it checked only whether that field was null:

Java
        if (authorizationCode.getExternalAuthorizationCode() != null) {
            authorizationCode.setCode(authorizationCode.getExternalAuthorizationCode());
        } else {
            generateAuthorizationCodeValue(authorizationCode, keyStatus.getAppCredential().getOrganizationName());
        }

Line by line:

  1. if (authorizationCode.getExternalAuthorizationCode() != null) asks: did an external code arrive?
  2. authorizationCode.setCode(authorizationCode.getExternalAuthorizationCode()); If yes, use it as the authorization code, unchanged.
  3. else { generateAuthorizationCodeValue(...); } If no, generate a random one.

A supplied value became the stored authorization code. Random generation ran only when the external field was null. The form value was already labelled "external," so Apigee stored it unchanged and never called the random generator. This is the moment the attacker's string became the real code that Apigee would later look up.

Step 8: the token paths build the same fallbacks

GenerateAccessTokenExecution built the same fallback resolvers in its constructor (lines 48 and 49):

Java
        this.accessTokenRef = buildRef(stepDefinition.getExternalAccessToken(), OAuthStepConstants.EXTERNAL_ACCESS_TOKEN);
        this.refreshTokenRef = buildRef(stepDefinition.getExternalRefreshToken(), OAuthStepConstants.EXTERNAL_REFRESH_TOKEN);

Line by line:

  1. this.accessTokenRef = buildRef(...) builds a resolver for the access token, using the same buildRef helper from step 3. If the policy has no ExternalAccessToken element, the fallback name is external_access_token.
  2. this.refreshTokenRef = buildRef(...) does the same for the refresh token, with the fallback name external_refresh_token.

So the access-token and refresh-token paths were not merely similar by name. They used the same helper, with the same "if not configured, look in the request" behaviour, just with different fixed keys.

Step 9: the flag does not guard either resolver

In GenerateAccessTokenExecution.execute (lines 72 to 74), ExternalAuthorization is recorded separately from artifact source selection, and both resolvers run against formParameters:

Java
        clientContext.setExternalAuthorization(((OAuthV2StepDefinition) this.stepDefinition).isExternalAuthorization());
        clientContext.setAccessToken(this.accessTokenRef.resolve(messageContext, formParameters));
        clientContext.setExternalRefreshToken(this.refreshTokenRef.resolve(messageContext, formParameters));

Line by line:

  1. clientContext.setExternalAuthorization(...) records the ExternalAuthorization flag on the context. This is the setting that decides whether client credentials are checked normally or by an external system. It is stored, but it does not gate the next two lines.
  2. clientContext.setAccessToken(this.accessTokenRef.resolve(messageContext, formParameters)); resolves the access token from the form map, exactly like the code path did.
  3. clientContext.setExternalRefreshToken(this.refreshTokenRef.resolve(messageContext, formParameters)); does the same for the refresh token.

The fixed keys changed to external_access_token and external_refresh_token; the trust decision did not. The flag was recorded, but it was not used to decide whether the fallback lookup should happen.

Step 10: the chosen code carried the victim's identity

For the first end-to-end test, an authorization code was chosen, then the victim test account submitted the authorization request while signed in. Apigee returned that same code and stored the victim's authorization behind it. Exchanging the known code produced an access token whose end_user was the victim.

In plain terms: the attacker picked the claim ticket number, the victim did the login, and the cloakroom attached the victim's coat to the attacker's ticket. The attacker, who already knew the ticket number, could then collect the coat.

The simplest proof used a client where the complete OAuth flow was controlled. A real confidential web application raised a harder objection: its client secret stays on the server, and PKCE ties the code exchange to a verifier that never appears in the browser. Knowing the code should not give an attacker either value. So the researcher built that harder version too.

Step 11: the confidential-client chain

The application used a backend for frontend. A normal login was begun in the attacker's browser. The BFF created the transaction, stored the state and PKCE verifier server-side, set a transaction cookie, and returned an authorization request containing the matching state and code challenge. At this point the attacker merely owned a valid login attempt.

Instead of submitting that request, its public parameters were placed into a cross-origin form for the victim. A cross-origin form is a form on one website that submits to a different website; browsers allow this, which is why login forms can post to a separate login server. The attacker's state and PKCE code challenge were preserved, and the chosen external_auth_code was added. The victim submitted the form while authenticated to the test SSO system. SSO (single sign-on) is a shared login used across several applications, so being signed in to the SSO means the login server already knows who you are.

Apigee then assembled a code record from three different owners: the attacker had chosen the code, the victim supplied the authenticated identity, and the code challenge belonged to the attacker's BFF transaction. That mixture is the whole problem. Each piece is legitimate on its own; together they bind the victim's identity to the attacker's transaction.

The first callback reached the BFF through the victim's browser. The BFF rejected it because that browser did not have the attacker's transaction cookie. That rejection showed the application's state handling was doing its job, but it did not invalidate the authorization code stored by Apigee. The code was still sitting in Apigee's storage, tied to the victim's identity, and the attacker knew its value.

The attacker already knew that code and still owned the original browser transaction. Opening the callback there gave the BFF the expected cookie and state. The BFF supplied its own client secret and the PKCE verifier it had stored at the beginning. The verifier matched the challenge attached to the chosen code, so Apigee returned tokens for the victim identity and the BFF created the attacker's application session as the victim.

Every control around the confidential client behaved as designed. The victim's callback was rejected. The client secret never entered either browser. State matched only in the attacker-owned transaction, and PKCE allowed only the party holding its verifier to redeem the code. The attacker was that party. The broken assumption sat one step earlier: Apigee had allowed the request to choose the identifier that joined the victim's authorization to the attacker's transaction.

The attack still required a usable authorization flow and a victim who submitted the authorization request while signed in. Supplying the form parameter alone did not authenticate anyone. What it supplied was the join key; the normal login and code exchange supplied everything around it.

Step 12: access-token fixation

In an implicit flow, where the authorization endpoint returns an access token directly, external_access_token was supplied before the victim authorized. An implicit flow is an older OAuth variant where the token comes straight back from the authorization step instead of being exchanged later. Apigee returned that exact opaque value, and presenting it to the identity endpoint resolved to the victim test account. This was the same shape as the code result: choose an identifier first, let Apigee attach the victim later.

Step 13: access-token rebinding

The test began with a known access-token value associated with the victim test account. Supplying that value during an authorization-code exchange under the attacker test account caused the identity endpoint to resolve the same string to the attacker afterwards. No new predictable token was needed; the existing identifier acquired a different owner. In everyday terms: the attacker did not mint a new key, they took an existing key and changed which door it opened.

Step 14: refresh-token rebinding

The before-and-after check was repeated with external_refresh_token. A refresh token that initially represented the victim became attached to attacker context, and refreshing it later produced an attacker-context access token.

Those last two results are why the researcher distinguishes fixation from rebinding. Fixation chooses the identifier before Apigee stores the identity. Rebinding starts with an identifier that already exists and changes the identity behind it. The unsafe input source was the same, but the OAuth operation determined what persistence did with the value.

The rebinding tests included one unglamorous complication: cache. A cache is a temporary copy of data kept close at hand so it can be served quickly. Token metadata could remain on an Apigee runtime node after the backing record changed. The tests either retried against another node or waited through the documented 180-second cache period before trusting the identity result. Without that wait, a test could read a stale answer and look like a failure when it was not.

Static inspection showed another refresh-token route during an authorization-code exchange. Static inspection means reading the code without running it. It was not included in the live proof because it required influence over the exchange request itself. It remains a code-supported variant, separate from the three behaviours that were reproduced.

Why it worked

The line that matters is not in a random-number generator or an OAuth cryptographic check. It is the generic fallback in buildRef(). When the proxy author named a flow variable, the helper read that explicit source. When the author named nothing, the helper did not stop. It looked in the caller's form under a conventional key.

That small default erased the distinction between an artifact imported deliberately by proxy logic and one volunteered by the HTTP client. Everything after it behaved consistently: the OAuth context carried a non-null external value, persistence honoured it, state matched, and PKCE verified the attacker's transaction.

None of the controls that usually attract attention had to be broken. The code was random when Apigee generated it. The client secret stayed secret. PKCE verified the correct verifier. The interesting question was earlier and much less glamorous: when a security-sensitive setting is absent, does the operation stop, or does some fallback quietly choose a new source?

What an attacker could do with it

An attacker who can get a victim to submit an authorization request while signed in can choose the authorization code, access token, or refresh token identifier that Apigee stores against the victim's authorization. With a confidential client using PKCE, the attacker can still redeem the code in their own browser transaction and obtain an application session as the victim, because the attacker controls the verifier and state that match the chosen code. The same input source allows fixation of access and refresh tokens, and rebinding of existing tokens to a different identity.

Supplying the form parameter alone does not authenticate anyone; it supplies the join key, and the normal login and code exchange supply everything around it. The rebinding results can be masked by the runtime cache, so identity checks may need a retry on another node or a wait through the documented 180-second cache period.

The fix

The report lists the issue as patched but does not describe the change. The behaviour at the centre of the finding is the fallback in buildRef(): when no external artifact element is configured, the resolver falls back to a request form key. The operation should either stop or use only an explicitly configured source, so that "not configured" cannot become a caller-controlled input.

Variants worth testing

These are follow-up checks based on the same pattern. They are useful because the same pattern may appear in other places.

  1. Other OAuthV2 artifact elements. Send external_access_token and external_refresh_token as form parameters on proxies that do not configure ExternalAccessToken or ExternalRefreshToken. A positive result is the redirect or token response returning the exact supplied value, and the identity endpoint resolving it to the victim account.
  2. Implicit flow fixation. Supply external_access_token before the victim authorizes in an implicit flow. A positive result is the authorization endpoint returning that exact opaque value and the identity endpoint resolving it to the victim.
  3. Rebinding an existing token. Take a known access or refresh token belonging to one account, supply it during an exchange under another account, then check the identity endpoint. A positive result is the same string resolving to the new owner after the cache period.
  4. Confidential client with PKCE. Start a login in the attacker's browser, capture the state and code challenge, place them with a chosen external_auth_code into a cross-origin form for the victim, then redeem the known code in the attacker's original transaction. A positive result is tokens for the victim identity issued to the attacker's BFF session.
  5. Refresh-token route during code exchange. Inspect the exchange path for a refresh-token resolver that runs against the exchange request. A positive result is a refresh token supplied in the exchange request being stored against the resulting authorization.

Glossary

  • API: a fixed way for one program to ask another program for data or actions over the internet.
  • API gateway: software that sits in front of services, checks and routes each request before it reaches them.
  • API proxy: the configuration inside a gateway that describes one service and the rules that run on its requests.
  • Access token: a short-lived pass that proves who you are when calling an API.
  • Authorization code: a short random string the login server gives the browser after login, later exchanged for tokens.
  • Authorization server: the part of a login system that authenticates the user and issues codes and tokens.
  • BFF (backend for frontend): a small server between the browser and the login system that keeps secrets and session state server-side.
  • Cache: a temporary copy of data kept for speed, which can briefly show old values after the real data changes.
  • Client secret: a password a server-side application uses to prove its identity to the login server; it never goes into the browser.
  • Code challenge: the scrambled version of a PKCE verifier sent with the login request.
  • Confidential client: an application that can keep a secret (such as a client secret) on a server.
  • Cookie: a small piece of data a site stores in your browser so it can recognise you on later requests.
  • Cross-origin form: a form on one website that submits to a different website.
  • Decompiling: turning a compiled program back into readable source code.
  • Fixation: an attacker choosing an identifier before the server stores an identity behind it.
  • Flow variable: a named slot inside Apigee that holds a value during a request.
  • Form parameter: a name and value sent in the body of a form submission.
  • Implicit flow: an older OAuth variant where the authorization step returns an access token directly.
  • Map: a lookup table of names to values.
  • OAuth: the standard that lets apps log you in through another service without sharing your password.
  • PKCE: an OAuth protection where the application proves it holds a secret verifier before redeeming a code.
  • Policy: a small rule that runs during a request in an API gateway.
  • Rebinding: changing which identity an already-existing identifier points to.
  • Refresh token: a longer-lived pass used to get a new access token when the old one expires.
  • Resolver: a small object whose job is to produce a value when asked.
  • Runtime: the running version of the software, identified here as 1-17-0-apigee-6.
  • SSO (single sign-on): a shared login used across several applications.
  • State: a random value an application sends with a login request and checks on return, to confirm the answer belongs to its own transaction.
  • Static inspection: reading code without running it.
  • Token: a pass that proves who you are on later requests.
  • Trust boundary: the line between data the system controls and data an outside party can supply.
  • Verifier: the secret random string in PKCE that only the application knows and presents when redeeming a code.

More by Nikita Markevich

View all

11 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.