Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: close CGNAT (100.64/10) + IPv4-compatible-IPv6 gaps in blockPrivate (#2046)

Adam Eivy892b6f8c9d79
diff --git a/server/lib/safeUrlFetch.js b/server/lib/safeUrlFetch.js
index c7e37bff6b..c741bc8eea 100644
--- a/server/lib/safeUrlFetch.js
+++ b/server/lib/safeUrlFetch.js
@@ -44,15 +44,22 @@ function isPrivateAddress(ip) {
const lower = ip.toLowerCase();
if (lower.includes(':')) {
if (lower === '::1' || lower === '::') return true;
- // IPv4-mapped IPv6 — both ::ffff:a.b.c.d (raw dns.resolve form) and
- // ::ffff:wxyz:wxyz (the hex form URL parsing normalizes to).
- const mappedDotted = lower.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
- if (mappedDotted) return isPrivateAddress(mappedDotted[1]);
- const mappedHex = lower.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
- if (mappedHex) {
- const high = parseInt(mappedHex[1], 16);
- const low = parseInt(mappedHex[2], 16);
- return isPrivateAddress(`${(high >> 8) & 0xff}.${high & 0xff}.${(low >> 8) & 0xff}.${low & 0xff}`);
+ // Embedded IPv4 — IPv4-mapped (::ffff:…) OR the deprecated IPv4-compatible
+ // (::…) form, either dotted (::ffff:1.2.3.4) or the two-hextet form URL
+ // parsing normalizes to (::ffff:c0a8:101 AND the ffff-less ::c0a8:101 that
+ // `new URL('http://[::192.168.1.1]')` yields). Decode and re-check as IPv4 so
+ // a private v4 embedded in an IPv6 literal can't slip past. Mirrors the
+ // embedded-v4 handling in catalogValidation.isBlockedIngestHost.
+ const embedded = /^::(?:ffff:)?(.+)$/i.exec(lower);
+ if (embedded) {
+ const tail = embedded[1];
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(tail)) return isPrivateAddress(tail);
+ const parts = tail.split(':');
+ if (parts.length === 2 && parts.every((p) => /^[0-9a-f]{1,4}$/.test(p))) {
+ const hi = parseInt(parts[0], 16);
+ const lo = parseInt(parts[1], 16);
+ return isPrivateAddress(`${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`);
+ }
}
const firstGroup = lower.split(':')[0];
if (firstGroup) {
@@ -69,6 +76,7 @@ function isPrivateAddress(ip) {
if (parts[0] === 10) return true;
if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) return true;
if (parts[0] === 192 && parts[1] === 168) return true;
+ if (parts[0] === 100 && parts[1] >= 64 && parts[1] <= 127) return true; // CGNAT 100.64/10 (Tailscale et al.)
if (parts[0] === 169 && parts[1] === 254) return true;
if (parts[0] === 127) return true;
if (parts[0] === 0) return true;
diff --git a/server/lib/safeUrlFetch.test.js b/server/lib/safeUrlFetch.test.js
index 8d85769bac..c000e6fde2 100644
--- a/server/lib/safeUrlFetch.test.js
+++ b/server/lib/safeUrlFetch.test.js
@@ -71,6 +71,23 @@ describe('isPublicHttpUrlSafe — strict blockPrivate posture', () => {
it('rejects an IPv6 ULA literal under blockPrivate', async () => {
expect(await isPublicHttpUrlSafe('http://[fd12:3456:789a::1]/x', { blockPrivate: true })).toBe(false);
});
+ it('rejects a CGNAT 100.64/10 literal (Tailscale) under blockPrivate', async () => {
+ expect(await isPublicHttpUrlSafe('http://100.100.100.200/x', { blockPrivate: true })).toBe(false);
+ expect(await isPublicHttpUrlSafe('http://100.64.0.1/x', { blockPrivate: true })).toBe(false);
+ // 100.63.x / 100.128.x are public — must NOT be blocked (literal, no resolve).
+ expect(await isPublicHttpUrlSafe('http://100.63.0.1/x', { blockPrivate: true })).toBe(true);
+ expect(await isPublicHttpUrlSafe('http://100.128.0.1/x', { blockPrivate: true })).toBe(true);
+ });
+ it('rejects a CGNAT/private address a hostname RESOLVES to under blockPrivate', async () => {
+ lookupMock.mockResolvedValue({ address: '100.100.42.7', family: 4 });
+ expect(await isPublicHttpUrlSafe('https://tailnet.example.com/x', { blockPrivate: true })).toBe(false);
+ });
+ it('rejects the deprecated IPv4-compatible IPv6 form of a private v4 under blockPrivate', async () => {
+ // new URL('http://[::192.168.1.1]') normalizes to hostname [::c0a8:101] —
+ // the ffff-less compatible form. It must still decode to 192.168.1.1.
+ expect(await isPublicHttpUrlSafe('http://[::192.168.1.1]/x', { blockPrivate: true })).toBe(false);
+ expect(await isPublicHttpUrlSafe('http://[::10.0.0.1]/x', { blockPrivate: true })).toBe(false);
+ });
it('rejects a hostname that RESOLVES to a private address under blockPrivate', async () => {
lookupMock.mockResolvedValue({ address: '10.0.0.42', family: 4 });
expect(await isPublicHttpUrlSafe('https://home.example.com/x', { blockPrivate: true })).toBe(false);