Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Push endpoints: judge NAT64, 6to4 and IPv4-compatible literals by their IPv4

Duarte Santos6fa1608706de
diff --git a/api/server.js b/api/server.js
index 88ca67969..6629e7b62 100644
--- a/api/server.js
+++ b/api/server.js
@@ -289,6 +289,7 @@ function isPrivateAddr(ip) {
if (a === 192 && b === 168) return true; // private
if (a === 192 && b === 0) return true; // 192.0.0.0/24, 192.0.2.0/24
if (a === 100 && b >= 64 && b <= 127) return true; // CGNAT
+ if (a === 198 && (b === 18 || b === 19)) return true; // benchmarking 198.18.0.0/15
if (a >= 224) return true; // multicast + reserved
return false;
}
@@ -302,7 +303,17 @@ function isPrivateAddr(ip) {
}
if (g.slice(0, 7).every(x => x === 0) && g[7] <= 1) return true; // unspecified, loopback
if ((g[0] & 0xffc0) === 0xfe80) return true; // link-local fe80::/10
+ if ((g[0] & 0xffc0) === 0xfec0) return true; // site-local fec0::/10 (deprecated, still routed by some)
if ((g[0] & 0xfe00) === 0xfc00) return true; // unique local fc00::/7
+ if ((g[0] & 0xff00) === 0xff00) return true; // multicast ff00::/8
+ // The forms that carry an IPv4 address inside: on a host with NAT64 or a 6to4 relay they reach
+ // that IPv4 address, so they are judged by it. 64:ff9b:1::/48 is the local-use NAT64 prefix,
+ // which only ever translates into a network of the operator's own.
+ const v4 = (hi, lo) => isPrivateAddr(`${hi >> 8}.${hi & 255}.${lo >> 8}.${lo & 255}`);
+ if (g.slice(0, 6).every(x => x === 0)) return v4(g[6], g[7]); // IPv4-compatible ::a.b.c.d
+ if (g[0] === 0x64 && g[1] === 0xff9b && g.slice(2, 6).every(x => x === 0)) return v4(g[6], g[7]); // NAT64 64:ff9b::/96
+ if (g[0] === 0x64 && g[1] === 0xff9b && g[2] === 1) return true; // local-use NAT64 64:ff9b:1::/48
+ if (g[0] === 0x2002) return v4(g[1], g[2]); // 6to4 2002::/16
return false;
}
diff --git a/api/test/server-push-filter.test.js b/api/test/server-push-filter.test.js
index 33deaa965..92fba3b40 100644
--- a/api/test/server-push-filter.test.js
+++ b/api/test/server-push-filter.test.js
@@ -68,14 +68,21 @@ test('subscribe refuses every spelling of a private IP literal and accepts publi
'https://[::1]/x', // loopback, compressed
'https://[fe80::1]/x', // link-local
'https://[fd00::1]/x', // unique local
- 'https://127.0.0.1/x' // plain IPv4 (the case that always worked)
+ 'https://127.0.0.1/x', // plain IPv4 (the case that always worked)
+ 'https://[::127.0.0.1]/x', // IPv4-compatible loopback
+ 'https://[64:ff9b::a9fe:a9fe]/x', // NAT64 of 169.254.169.254
+ 'https://[64:ff9b:1::1]/x', // local-use NAT64
+ 'https://[2002:a00:1::1]/x', // 6to4 of 10.0.0.1
+ 'https://[fec0::1]/x', // site-local
+ 'https://[ff02::1]/x', // multicast
+ 'https://198.18.0.1/x' // benchmarking range
];
for (const ep of privateForms) {
const r = await subscribe(ep);
assert.equal(r.status, 400, ep);
assert.deepEqual(await r.json(), { error: 'endpoint must not point at a private address' }, ep);
}
- for (const ep of ['https://[::ffff:8.8.8.8]/x', 'https://[::ffff:808:808]/x', 'https://[2606:4700::1111]/x', 'https://8.8.8.8/x', 'https://push.example/x']) {
+ for (const ep of ['https://[64:ff9b::808:808]/x', 'https://[2002:808:808::1]/x', 'https://[::ffff:8.8.8.8]/x', 'https://[::ffff:808:808]/x', 'https://[2606:4700::1111]/x', 'https://8.8.8.8/x', 'https://push.example/x']) {
assert.equal((await subscribe(ep)).status, 200, ep);
}
});