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

address review (agy): treat all loopback and private IPv6 endpoints as private

Adam Eivy199a2fd1c8a3
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index aa5da2816c..7bdb1b4e2e 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -682,7 +682,12 @@ export const localBackendForProvider = (provider) => {
return null;
};
-const LOCAL_ENDPOINT_RE = /^(https?:\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0|\[?::1\]?)(:|\/|$)/i;
+// The whole loopback block (`127.0.0.0/8`), not just `127.0.0.1` — a daemon on a
+// loopback alias (`127.0.0.2`) is as local as one on `.1`, and the server's
+// `isLocalInstanceHost` already accepts the full block. While they disagreed, a
+// provider on `http://127.0.0.2:11434` was badged NEEDS SETUP for an API key a
+// loopback endpoint never needs.
+const LOCAL_ENDPOINT_RE = /^(https?:\/\/)?(localhost|127\.\d{1,3}\.\d{1,3}\.\d{1,3}|0\.0\.0\.0|\[?::1\]?|\[?::\]?)(:|\/|$)/i;
export const isLocalEndpoint = (endpoint) =>
typeof endpoint === 'string' && LOCAL_ENDPOINT_RE.test(endpoint.trim());
@@ -693,6 +698,25 @@ export const isLocalEndpoint = (endpoint) =>
// is a first-class configuration, not an edge case).
const PRIVATE_IP_RE = /^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.|169\.254\.|100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.)/;
+/**
+ * IPv6 counterpart to {@link PRIVATE_IP_RE}: unique-local (`fc00::/7`) and
+ * link-local (`fe80::/10`). Tailscale hands out a ULA address alongside the
+ * CGNAT v4 one, so without this a tailnet peer reached over IPv6 read as a
+ * public host and its keyless provider was blocked on a missing API key.
+ *
+ * Gated on the host being an IPv6 literal (it contains a `:`) and compared
+ * NUMERICALLY on the leading hextet — a bare `/^f[cd]/` prefix test would also
+ * claim hostnames like `fdrive.example.com`, and `fd::1` expands to a leading
+ * hextet of `0x00fd`, which is not in `fc00::/7` at all.
+ */
+const isPrivateIpv6 = (host) => {
+ if (!host.includes(':')) return false;
+ const first = host.split(':')[0];
+ if (!/^[0-9a-f]{1,4}$/.test(first)) return false; // '' for `::1` — loopback, already matched above
+ const n = parseInt(first, 16);
+ return (n >= 0xfc00 && n <= 0xfdff) || (n >= 0xfe80 && n <= 0xfebf);
+};
+
/**
* Is this endpoint inside the private network — loopback, a LAN/tailnet address,
* a `.local`/`.ts.net`/`.internal` name, or a bare single-label host?
@@ -717,6 +741,7 @@ export const isPrivateNetworkEndpoint = (endpoint) => {
if (!URL.canParse(candidate)) return false;
const host = new URL(candidate).hostname.toLowerCase().replace(/^\[|\]$/g, '');
if (PRIVATE_IP_RE.test(host)) return true;
+ if (isPrivateIpv6(host)) return true;
if (/\.(local|internal|lan|home\.arpa|ts\.net)$/.test(host)) return true;
// A single-label host resolves only inside the local network (`http://nas:11434`).
return !host.includes('.') && !host.includes(':');
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 67e76f12fc..7d41cbaac5 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -485,6 +485,17 @@ describe('isLocalEndpoint', () => {
expect(isLocalEndpoint('localhost:11434')).toBe(true);
});
+ it('matches the whole loopback block, not just 127.0.0.1', () => {
+ // A daemon on a loopback alias is as local as one on `.1`, and the server's
+ // `isLocalInstanceHost` accepts the full block — while they disagreed, a
+ // provider on 127.0.0.2 was badged NEEDS SETUP for a key it never needs.
+ expect(isLocalEndpoint('http://127.0.0.2:11434/v1')).toBe(true);
+ expect(isLocalEndpoint('http://127.5.5.5:8080')).toBe(true);
+ expect(isLocalEndpoint('http://[::]:1234')).toBe(true);
+ // …without letting a loopback prefix vouch for a public host.
+ expect(isLocalEndpoint('http://127.0.0.1.evil.com/v1')).toBe(false);
+ });
+
it('rejects hosted endpoints and non-strings', () => {
expect(isLocalEndpoint('https://api.cerebras.ai/v1')).toBe(false);
expect(isLocalEndpoint('https://api.openai.com/v1')).toBe(false);
@@ -1300,6 +1311,13 @@ describe('isPrivateNetworkEndpoint', () => {
'http://host.local:1234',
'http://box.internal/v1',
'http://ollama',
+ // IPv6 unique-local — Tailscale hands out a ULA address alongside the CGNAT
+ // v4 one, so a tailnet peer reached over IPv6 must not read as public.
+ 'http://[fd7a:115c:a1e0::1]:11434/v1',
+ 'http://[fc00::5]:1234',
+ // IPv6 link-local (fe80::/10).
+ 'http://[fe80::1]:1234',
+ 'http://[febf::1]:1234',
])('treats %s as inside the private network', (endpoint) => {
expect(isPrivateNetworkEndpoint(endpoint)).toBe(true);
});
@@ -1312,6 +1330,14 @@ describe('isPrivateNetworkEndpoint', () => {
'http://172.32.0.1:11434',
'http://100.128.0.1:11434',
'http://9.9.9.9/v1',
+ // A HOSTNAME starting with fc/fd is not an IPv6 ULA — a bare prefix test on
+ // the host would hand these the no-key-needed pass.
+ 'https://fdrive.example.com:1234/v1',
+ 'https://fc-api.example.com/v1',
+ // 2001:… is public IPv6, and `fd::1` expands to a leading hextet of 0x00fd,
+ // which is outside fc00::/7 despite the `fd` spelling.
+ 'http://[2001:db8::1]:1234',
+ 'http://[fd::1]:1234',
'',
null,
])('treats %s as public', (endpoint) => {