SSRF protection bypass via IPv6 transition addresses (NAT64 / 6to4 / Teredo) in sector_identifier_uri and client_id URL validation
Description
SSRF protection bypass via IPv6 transition addresses (NAT64 / 6to4 / Teredo) in sector_identifier_uri and client_id URL validation
Summary
The isPrivateAddress methods in both SectorIdentifierUriService and ClientIdMetadataService use Java's InetAddress methods (isLoopbackAddress, isSiteLocalAddress, isLinkLocalAddress, isAnyLocalAddress, isMulticastAddress) plus a manual ULA check (fc00::/7), but do not recognize IPv6 transition addresses (NAT64, 6to4, Teredo) that embed private IPv4 destinations. An attacker can register an OpenID Connect client with a sector_identifier_uri or client_id URL using a NAT64/6to4 address to make the auth server fetch from internal services.
Affected component / versions
- Package:
JanssenProject/jans(jans-auth-server) - Affected versions: all versions including current HEAD (
ec4c0ba74bf0) - Vulnerable files:
jans-auth-server/server/src/main/java/io/jans/as/server/service/net/SectorIdentifierUriService.javaL95-106jans-auth-server/server/src/main/java/io/jans/as/server/service/ClientIdMetadataService.javaL359-364
Details
Root cause (CWE-918)
SectorIdentifierUriService.java:95-106:
boolean isPrivateAddress(InetAddress address) {
if (address.isLoopbackAddress()
|| address.isSiteLocalAddress()
|| address.isLinkLocalAddress()
|| address.isAnyLocalAddress()
|| address.isMulticastAddress()) {
return true;
}
byte[] bytes = address.getAddress();
return bytes.length == 16 && (bytes[0] & 0xFE) == 0xFC; // fc00::/7 ULA
}ClientIdMetadataService.java:359-364:
public boolean isPrivateAddress(InetAddress address) {
return address.isLoopbackAddress() ||
address.isSiteLocalAddress() ||
address.isLinkLocalAddress() ||
address.isAnyLocalAddress();
}The ClientIdMetadataService version is even weaker -- no multicast check and no ULA check.
For 64:ff9b::a9fe:a9fe (NAT64 encoding of 169.254.169.254):
isLoopbackAddress()= falseisSiteLocalAddress()= false (checks fec0::/10, not NAT64)isLinkLocalAddress()= false (checks fe80::/10)isAnyLocalAddress()= falseisMulticastAddress()= false- ULA:
(0x00 & 0xFE)= 0x00 != 0xFC -> false - Result: NOT private -> bypass
Reachability / trust boundary
Both services validate URLs provided during OpenID Connect Dynamic Client Registration (RFC 7591):
sector_identifier_uri: fetched by the auth server to retrieve the list of redirect URIs for pairwise subject identifiersclient_idURL (OAuth 2.0 Client ID URL): fetched to retrieve client metadata
The project explicitly validates these URLs against private addresses to prevent SSRF (the methods are called isPrivateAddress / isPrivateOrUnresolvableHost). The SectorIdentifierUriService even resolves ALL DNS records (not just the first) and fails closed on resolution failure. This indicates a deliberate SSRF defense that the IPv6 transition addresses bypass.
Attack chain
- Attacker sends Dynamic Client Registration request with
sector_identifier_uri: "http://[64:ff9b::a9fe:a9fe]/latest/meta-data/iam/security-credentials/" SectorIdentifierUriService.isPrivateOrUnresolvableHostresolves the hostisPrivateAddresschecks the resolved IPv6 address -- all checks failfetchSectorIdentifierContentmakes HTTP GET to the NAT64 address- Response contains cloud metadata (IAM credentials if AWS)
Impact
An attacker capable of OpenID Connect Dynamic Client Registration can bypass the SSRF protection to:
- Read cloud instance metadata including IAM credentials from the auth server's network
- Access internal services behind the auth server
- Probe internal network topology via DNS resolution + connection
The sector_identifier_uri is fetched with a 30-second read timeout, giving a large window for internal service interaction. The response content is parsed as JSON, so JSON-returning endpoints (like cloud metadata) will have their content processed.
Severity: HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N = 8.6 -- note: Dynamic Client Registration may be unauthenticated)
Proof of concept (code-level verification)
Java trace:
InetAddress addr = InetAddress.getByName("64:ff9b::a9fe:a9fe");
// Inet6Address, bytes = [0x00,0x64,0xff,0x9b, 0,0,0,0, 0,0,0,0, 0xa9,0xfe,0xa9,0xfe]
addr.isLoopbackAddress() -> false
addr.isSiteLocalAddress() -> false (checks fec0::/10)
addr.isLinkLocalAddress() -> false (checks fe80::/10)
addr.isAnyLocalAddress() -> false
addr.isMulticastAddress() -> false
// ULA: (0x00 & 0xFE) = 0x00 != 0xFC -> false
// isPrivateAddress returns false -> BYPASSNegative control:
InetAddress addr = InetAddress.getByName("10.0.0.1");
addr.isSiteLocalAddress() -> true -> BLOCKED
InetAddress addr6 = InetAddress.getByName("fc00::1");
// ULA: (0xFC & 0xFE) = 0xFC -> true -> BLOCKEDRemediation / fix
Add NAT64/6to4/Teredo extraction and re-check:
boolean isPrivateAddress(InetAddress address) {
if (address.isLoopbackAddress() || address.isSiteLocalAddress()
|| address.isLinkLocalAddress() || address.isAnyLocalAddress()
|| address.isMulticastAddress()) {
return true;
}
byte[] bytes = address.getAddress();
if (bytes.length == 16) {
if ((bytes[0] & 0xFE) == 0xFC) return true; // ULA
// Extract embedded IPv4 from transition addresses
try {
InetAddress embedded = extractTransitionIpv4(bytes);
if (embedded != null) return isPrivateAddress(embedded);
} catch (Exception e) { return true; }
}
return false;
}Both SectorIdentifierUriService and ClientIdMetadataService should share a common implementation. The ClientIdMetadataService version also needs multicast and ULA checks added.
Credit
Reported by tonghuaroot (tonghuaroot@gmail.com).