Research details · Patched
- Product
- Google Cloud Apigee / AccessControl policy
- Affected versions
- v1-15-0-apigee-1
- Patch status
- Patched
- Bounty
- USD 7,500
- Reported
- Apr 27, 2025
Apigee has separate implementations for IPv4 and IPv6 ranges in its AccessControl policy. The IPv4 version looked exactly as boring as an IP allow-list should: build a mask, calculate the lower and upper bounds, compare the address.
The IPv6 constructor did something else. It walked through the address four bits at a time.
That was an odd choice, but not necessarily a bug. IPv6 is commonly written in hexadecimal, and one hex digit represents four bits. The problem appeared in the two conditions repeated for every byte:
if (mask >= 4) {
mask -= 4;
// copy the nibble into low and high
} else {
// leave low at zero, fill high with ones
}There was no case for one, two, or three remaining network bits.
I stopped at that branch for a while. A valid IPv6 prefix can end after any of the 128 bits, so what exactly would Apigee do with /127?
/127 left three bits behind
IP6AddressRange represented each configured network as two BigInteger values: low and high. It parsed the IPv6 address into sixteen bytes, then handled the high and low nibble of every byte separately. The complete constructor branch looked like this:
if (mask >= 4) {
mask -= 4;
BigInteger higherBits = BigInteger.valueOf(b & 240);
this.low = this.low.or(higherBits.shiftLeft(order));
this.high = this.high.or(higherBits.shiftLeft(order));
} else {
this.high = this.high.or(BigInteger.valueOf(240L).shiftLeft(order));
}
if (mask >= 4) {
mask -= 4;
BigInteger lowerBits = BigInteger.valueOf(b & 15);
this.low = this.low.or(lowerBits.shiftLeft(order));
this.high = this.high.or(lowerBits.shiftLeft(order));
} else {
this.high = this.high.or(BigInteger.valueOf(15L).shiftLeft(order));
}With at least four mask bits remaining, the constructor copied the complete nibble from the address into both bounds and subtracted four. Otherwise, it copied nothing: low kept four zeroes, and high received four ones.
Now take 2001:db8::/127. After fifteen complete bytes, seven mask bits remain for the final byte. The first branch copies its high nibble and reduces the mask to three. The second mask >= 4 check fails, so the final three network bits disappear together with the one actual host bit.
That produces a much larger interval:
configured: 2001:db8::/127
intended: 2001:db8::0 - 2001:db8::1
constructed: 2001:db8::0 - 2001:db8::fThe constructed range is /124. At this point I had a clear hypothesis: Apigee would treat /127 and /124 as the same allow-list.
A small Java test made the ranges identical
Before involving a proxy, I copied the range calculation into a standalone Java program. One implementation followed Apigee's nibble loop; the other built the bounds with a bit-level mask. I asked both of them whether 2001:db8::f belonged to 2001:db8::/127:
Apigee-style range (2001:db8::/127):
low = 20010db8000000000000000000000000
high = 20010db800000000000000000000000f
Bitmask range (2001:db8::/127):
low = 20010db8000000000000000000000000
high = 20010db8000000000000000000000001
Test address 2001:db8::f:
Apigee-style match: true
Bitmask match: falseThe calculation behaved exactly as the branch suggested. It still left one useful question: did the surrounding AccessControl policy validate, normalize, or reject the range before using it?
The Apigee documentation accepts IPv6 masks from 1 through 128. It even notes that values outside the tidy hexadecimal boundaries can be used for finer control. /127 was valid configuration, not an unsupported input I had forced into an internal class.
The live policy let ::f through
I built two equivalent proxy flows. /acl/124 used an allow rule for 2001:db8::/124; /acl/127 used 2001:db8::/127. For this test, both policies read the candidate client address from a custom ip header. That let me switch addresses without arranging several IPv6 network interfaces.
First I sent 2001:db8::f to /acl/124. Apigee returned HTTP 200, as expected: ::f is the last address in that range.
Then I sent the same value to /acl/127:
GET /acl/127 HTTP/1.1
Host: <test Apigee host>
ip: 2001:0db8:0000:0000:0000:0000:0000:000fA correct /127 contains only ::0 and ::1, so this request should have missed the allow rule and returned HTTP 403. It returned HTTP 200. The policy had not repaired or rejected the constructor's range; it had used it for the authorization decision.
The custom header was only part of the test harness. A normally configured policy can evaluate the requester's actual IPv6 source address. An attacker therefore did not need to spoof a forwarding header: an address from the widened part of the configured network was enough.
Every partial hex digit widened the rule
/127 made the error easy to see, but the same branch affected every prefix length not divisible by four. The effective prefix was rounded down to the preceding nibble boundary:
effective prefix = floor(configured prefix / 4) * 4One discarded network bit doubled the range, two bits made it four times larger, and three bits made it eight times larger. /65, /73, /125, and /126 all followed the same pattern.
For an ALLOW rule, those extra addresses became authorized. A proxy developer could believe that an internal API or administrative route was restricted to a narrow IPv6 network while Apigee admitted clients from the surrounding range. Exploitation required knowledge of the configured allow-list and control of an IPv6 address inside the added portion. It did not require membership in the proxy owner's Google Cloud organization merely to call a public proxy.
The arithmetic widened DENY rules as well. In that direction it blocked more clients than intended rather than producing this authorization bypass.
What stayed with me was how reasonable the loop looked at first glance. IPv6 is printed as hexadecimal, and the code followed those printed digits faithfully. The policy contract was measured in bits. For /127, the three bits between those two models were exactly the addresses the allow-list was supposed to keep out.