Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(security): block IETF-reserved 0000::/3 in the SSRF guard
Yudhi Armyndharisab3d70ac6e22
diff --git a/src/common/security/ssrf-guard.spec.ts b/src/common/security/ssrf-guard.spec.tsindex 22f576ebe..cbea33f4b 100644--- a/src/common/security/ssrf-guard.spec.ts+++ b/src/common/security/ssrf-guard.spec.ts@@ -43,6 +43,8 @@ describe('isBlockedAddress', () => {['fe80::1', 'IPv6 link-local'],['fec0::1', 'IPv6 site-local fec0::/10 (deprecated, RFC 3879)'],['feff::1', 'IPv6 site-local upper bound feff'],+ ['fc0::1', 'IETF-reserved 0000::/3 — not ULA despite the fc prefix'],+ ['fe8::1', 'IETF-reserved 0000::/3 — not link-local despite the fe prefix'],['::ffff:127.0.0.1', 'IPv4-mapped loopback (dotted)'],['::ffff:7f00:1', 'IPv4-mapped loopback (hex)'],['::ffff:0a00:0001', 'IPv4-mapped RFC1918 (hex, zero-padded)'],@@ -74,6 +76,7 @@ describe('isBlockedAddress', () => {['172.32.0.1', 'just outside 172.16/12'],['2001:4860:4860::8888', 'public IPv6'],['::ffff:0808:0808', 'IPv4-mapped public 8.8.8.8 (hex)'],+ ['::ffff:8.8.8.8', 'IPv4-mapped public 8.8.8.8 (dotted) — the reserved-block catch must not swallow it'],['2002:0808:0808::', '6to4 of public 8.8.8.8 stays allowed'],['64:ff9b::0808:0808', 'NAT64 of public 8.8.8.8 stays allowed'],['::ffff:0:0808:0808', 'IPv4-translatable public 8.8.8.8 stays allowed'],diff --git a/src/common/security/ssrf-guard.ts b/src/common/security/ssrf-guard.tsindex d65b79c57..0c1819fb2 100644--- a/src/common/security/ssrf-guard.ts+++ b/src/common/security/ssrf-guard.ts@@ -89,6 +89,9 @@ const BLOCKED_V4_RANGES: ReadonlyArray<readonly [string, number]> = [const BLOCKED_V6_RANGES: ReadonlyArray<readonly [string, number]> = [['::', 128], // unspecified['::1', 128], // loopback+ ['0000::', 3], // reserved by IETF (RFC 4291: global unicast is 2000::/3) — ::, ::1 and the+ // IPv4-embedding forms return earlier via the ladder or their own entries, so the fallthrough+ // check only catches the rest of the block (e.g. 1::, fc0::, fe8::)['fc00::', 7], // ULA (RFC 4193)['fe80::', 10], // link-local['fec0::', 10], // deprecated site-local (RFC 3879)@@ -208,9 +211,10 @@ export function isBlockedAddress(ip: string): boolean {}}- // Reserved-range membership (unspecified, loopback, ULA, link-local, deprecated site-local) via- // the stdlib BlockList — numeric, so compressed and fully-expanded spellings of the same- // address answer alike. Embedded forms already returned above (public embeddings stay allowed).+ // Reserved-range membership (unspecified, loopback, ULA, link-local, deprecated site-local,+ // IETF-reserved 0000::/3) via the stdlib BlockList — numeric, so compressed and fully-expanded+ // spellings of the same address answer alike. Embedded forms already returned above (public+ // embeddings, NAT64 included, stay allowed — only the ladder decides those).return BLOCKED_V6.check(lower, 'ipv6');}