Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(ssrf): block NAT64 addresses outside the /96 layouts

Yudhi Armyndharis5172ecd7eb2c
diff --git a/src/common/security/ssrf-guard.spec.ts b/src/common/security/ssrf-guard.spec.ts
index ab5983e22..41f7af9ff 100644
--- a/src/common/security/ssrf-guard.spec.ts
+++ b/src/common/security/ssrf-guard.spec.ts
@@ -55,6 +55,9 @@ describe('isBlockedAddress', () => {
['64:ff9b::a9fe:a9fe', 'NAT64 of cloud metadata 169.254.169.254'],
['64:ff9b::7f00:1', 'NAT64 of loopback 127.0.0.1'],
['64:ff9b::127.0.0.1', 'NAT64 of loopback (dotted tail)'],
+ ['64:ff9b:1::7f00:1', 'local-use NAT64 /96 of loopback 127.0.0.1'],
+ ['64:ff9b:1:7f00:0:100:808:808', 'local-use NAT64 /48 layout embedding loopback 127.0.0.1'],
+ ['64:ff9b:1:a00:0:100:808:808', 'local-use NAT64 /48 layout embedding RFC1918 10.0.0.1'],
['2002:7f00:1::', '6to4 of loopback 127.0.0.1'],
['2002:a9fe:a9fe::', '6to4 of cloud metadata 169.254.169.254'],
['2002:0a00:0001::', '6to4 of RFC1918 10.0.0.1'],
@@ -84,6 +87,7 @@ describe('isBlockedAddress', () => {
['::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'],
+ ['64:ff9b:1::808:808', 'local-use NAT64 /96 of public 8.8.8.8 stays allowed'],
['::ffff:0:0808:0808', 'IPv4-translatable public 8.8.8.8 stays allowed'],
['0:0:0:0:0:ffff:0808:0808', 'fully-expanded IPv4-mapped public 8.8.8.8 stays allowed (hex)'],
['0:0:0:0:0:ffff:8.8.8.8', 'fully-expanded IPv4-mapped public 8.8.8.8 stays allowed (dotted)'],
diff --git a/src/common/security/ssrf-guard.ts b/src/common/security/ssrf-guard.ts
index d7893d0ce..e04f283a9 100644
--- a/src/common/security/ssrf-guard.ts
+++ b/src/common/security/ssrf-guard.ts
@@ -190,7 +190,17 @@ export function isBlockedAddress(ip: string): boolean {
if (hextets[0] === 0x2002) {
return isBlockedAddress(hextetsToV4(hextets[1], hextets[2])); // 6to4
}
- if (hextets[0] === 0x64 && hextets[1] === 0xff9b) {
+ // NAT64 /96: the well-known 64:ff9b::/96 and the local-use 64:ff9b:1::/96 (RFC 8215). Any other
+ // 64:ff9b layout (a /48 local-use prefix embeds the IPv4 in the middle hextets) falls through to
+ // the reserved-range check below and is blocked.
+ if (
+ hextets[0] === 0x64 &&
+ hextets[1] === 0xff9b &&
+ hextets[2] <= 1 &&
+ hextets[3] === 0 &&
+ hextets[4] === 0 &&
+ hextets[5] === 0
+ ) {
return isBlockedAddress(hextetsToV4(hextets[6], hextets[7])); // NAT64
}
if (hextets.slice(0, 6).every(h => h === 0) && (hextets[6] | hextets[7]) !== 0) {