# When /127 Quietly Became /124

Apigee's IPv6 CIDR parser rounded non-nibble-aligned prefixes down to the nibble boundary, so a /127 allow rule admitted addresses up to /124.

- Payout: $7,500
- Severity: medium
- Program: Google
- Found by: Nikita Markevich
- Disclosed: 2026-11-16
- Write-up quality: 8/10
- Original: https://bugs.exposed/posts/apigee-ipv6-cidr-rounding
- Library page: https://bugbountylibrary.com/r/blog%3Abugs-exposed-posts-apigee-ipv6-cidr-rounding
- Tags: area:cloud domain:cloud impact:internal-access kind:bounty platform:blog sev:medium tech:java technique:source-review vuln:access-control vuln:auth-bypass vuln:misconfiguration

**Target:** Apigee AccessControl policy IPv6 CIDR range parser (IP6AddressRange.java)
**Root cause:** The IPv6 range constructor consumed the mask four bits at a time and had no branch for 1-3 remaining bits, so leftover network bits were dropped and the effective prefix rounded down to the previous nibble boundary.
**Steps:**
1. Read IP6AddressRange.java: two `if (mask >= 4)` branches per byte; the else branch fills high with ones and leaves low at zero, discarding any remainder <4 bits.
2. Compute 2001:db8::/127: after 15 bytes, 7 mask bits remain; first branch copies high nibble, mask becomes 3, second branch fails, so 3 network bits vanish.
3. Reproduce in standalone Java: Apigee-style range gives low=...0000, high=...000f; bitmask range gives high=...0001; test address 2001:db8::f matches Apigee-style only.
4. Deploy two proxy flows /acl/124 (allow 2001:db8::/124) and /acl/127 (allow 2001:db8::/127), reading client IP from a custom `ip` header.
5. Send `GET /acl/127` with `ip: 2001:0db8:0000:0000:0000:0000:0000:000f`; expect 403 but receive HTTP 200, confirming the widened allow rule is used for authorization.
**How found:** Noticed the IPv6 constructor walked the mask four bits at a time unlike the IPv4 implementation, spotted the missing case for 1-3 remaining bits, and hypothesized /127 would behave as /124; validated arithmetic in standalone Java before testing a live proxy.
**Exploitation:** Attacker with an IPv6 address inside the widened portion of a configured allow-listed network (e.g. ::2-::f for a /127) reaches routes the proxy owner believed were restricted to a narrow prefix; no forwarding-header spoofing needed since the policy evaluates the real source address.
**Insight:** When a parser iterates in fixed-size units (nibbles, bytes, blocks), check what happens to a remainder smaller than one unit — non-aligned prefix lengths like /127, /126, /125 are where the loop silently drops bits and widens ranges.

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

**Live request to /127 allow rule with ::f**

```
GET /acl/127 HTTP/1.1
Host: <test Apigee host>
ip: 2001:0db8:0000:0000:0000:0000:0000:000f

A 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.
```

**Vulnerable nibble-parsing constructor branch**

```
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));
}
```

**Standalone Java range comparison test**

```
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: false
```

