Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(security): block CGNAT range (RFC 6598) in SSRF URL validation (#86093)

Rafael Audibert5bfd44086b6f
diff --git a/posthog/security/test/test_url_validation.py b/posthog/security/test/test_url_validation.py
index e2ab20d0f9e4..59459d94bd8e 100644
--- a/posthog/security/test/test_url_validation.py
+++ b/posthog/security/test/test_url_validation.py
@@ -118,9 +118,21 @@ class TestUrlValidation:
ok, err = uv.is_url_allowed("http://localhost")
assert ok and err is None
- def test_is_url_allowed_private_resolution_blocked(self, monkeypatch):
+ @pytest.mark.parametrize(
+ "resolved_ip",
+ [
+ "192.168.1.10",
+ # CGNAT (RFC 6598): neither is_private nor is_global, so the attribute flags
+ # alone let it through; guards the explicit _CGNAT_NETWORK check.
+ "100.64.0.1",
+ "100.127.255.255",
+ # IPv4-mapped form of a CGNAT address, which network membership alone misses.
+ "::ffff:100.64.0.1",
+ ],
+ )
+ def test_is_url_allowed_private_resolution_blocked(self, resolved_ip, monkeypatch):
def fake_resolve(host: str):
- return {ipaddress.ip_address("192.168.1.10")}
+ return {ipaddress.ip_address(resolved_ip)}
monkeypatch.setattr(uv, "resolve_host_ips", fake_resolve)
ok, err = uv.is_url_allowed("https://example.com")
diff --git a/posthog/security/url_validation.py b/posthog/security/url_validation.py
index 29a488acccbb..f735541bd628 100644
--- a/posthog/security/url_validation.py
+++ b/posthog/security/url_validation.py
@@ -122,8 +122,19 @@ def resolve_hosts_ips(hosts: Iterable[str]) -> dict[str, ResolvedIPs]:
return resolved
+# Carrier-grade NAT space (RFC 6598). ipaddress classifies it as neither private nor
+# global, so none of the attribute flags in _is_internal_ip catch it, yet it is routable
+# inside VPCs and overlay networks (e.g. Kubernetes pod ranges, Tailscale). It is
+# special-use per RFC 6890, which the CIMD spec requires blocking, so block it explicitly.
+_CGNAT_NETWORK = ipaddress.ip_network("100.64.0.0/10")
+
+
def _is_internal_ip(ip: ipaddress.IPv4Address | ipaddress.IPv6Address) -> bool:
"""Check if an IP address is internal/private and should be blocked."""
+ # An IPv4-mapped IPv6 address (::ffff:a.b.c.d) reaches the IPv4 host it embeds, and
+ # network membership does not cross IP versions, so judge the embedded address.
+ if isinstance(ip, ipaddress.IPv6Address) and ip.ipv4_mapped is not None:
+ ip = ip.ipv4_mapped
return any(
[
ip.is_private,
@@ -132,6 +143,7 @@ def _is_internal_ip(ip: ipaddress.IPv4Address | ipaddress.IPv6Address) -> bool:
ip.is_multicast,
ip.is_reserved,
ip.is_unspecified,
+ ip in _CGNAT_NETWORK,
]
)