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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: guard service catalog refresh against secret-endpoint exfiltration (#12495)
[._.]/ Adam Eivy7b04b0810d7a
diff --git a/server/lib/openAiModelsProbe.js b/server/lib/openAiModelsProbe.jsindex 0b659dfd6a..10528ecb57 100644--- a/server/lib/openAiModelsProbe.js+++ b/server/lib/openAiModelsProbe.js@@ -71,7 +71,14 @@ function shortFailureReason(err) {export async function probeOpenAiModels(baseUrl, { timeoutMs = 2_000, apiKey = '', headers = {} } = {}) {const url = `${String(baseUrl || '').replace(/\/+$/, '')}/models`;const merged = { ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}), ...headers };- const init = { method: 'GET', ...(Object.keys(merged).length > 0 ? { headers: merged } : {}) };+ // A redirect would forward custom credential headers (undici only strips+ // `Authorization` cross-origin), so a keyed probe fails instead of following one.+ const carriesKey = Object.keys(merged).some((name) => /^(authorization|x-api-key)$/i.test(name));+ const init = {+ method: 'GET',+ ...(Object.keys(merged).length > 0 ? { headers: merged } : {}),+ ...(carriesKey ? { redirect: 'error' } : {}),+ };const res = await fetchWithTimeout(url, init, timeoutMs)// undici reports every network failure as a bare `TypeError: fetch failed`;// the real reason (ECONNREFUSED vs. ETIMEDOUT — "nothing is listening" vs.diff --git a/server/lib/openAiModelsProbe.test.js b/server/lib/openAiModelsProbe.test.jsindex 0a7d3b28c8..7c5cf25896 100644--- a/server/lib/openAiModelsProbe.test.js+++ b/server/lib/openAiModelsProbe.test.js@@ -22,6 +22,14 @@ describe('probeOpenAiModels', () => {expect(fetchMock).toHaveBeenCalledWith('http://127.0.0.1:8080/v1/models', { method: 'GET' }, 1234);});+ it('refuses to follow redirects whenever a credential header is attached, and only then', async () => {+ const fetchMock = mockFetch(async () => jsonResponse({ data: [] }));+ await probeOpenAiModels('https://api.example.com/v1', { apiKey: 'example-key' });+ await probeOpenAiModels('https://api.example.com/v1', { headers: { 'x-api-key': 'example-key' } });+ await probeOpenAiModels('http://127.0.0.1:8080/v1');+ expect(fetchMock.mock.calls.map(([, init]) => init.redirect)).toEqual(['error', 'error', undefined]);+ });+it('reads both the OpenAI `data` shape and a bare `models` array', async () => {mockFetch(async () => jsonResponse({ data: [{ id: 'dflash' }, { name: 'qwen' }, 'bare-string', { id: '' }] }));await expect(probeOpenAiModels('http://x/v1')).resolves.toMatchObject({@@ -131,7 +139,7 @@ it('attaches a Bearer header only when a key is supplied', async () => {await probeOpenAiModels('http://127.0.0.1:18020/v1', { timeoutMs: 500, apiKey: 'vllm-key' });expect(fetchMock).toHaveBeenCalledWith('http://127.0.0.1:18020/v1/models',- { method: 'GET', headers: { Authorization: 'Bearer vllm-key' } },+ { method: 'GET', headers: { Authorization: 'Bearer vllm-key' }, redirect: 'error' },500,);diff --git a/server/routes/providers.services.test.js b/server/routes/providers.services.test.jsindex be757a617e..3bf932ca3c 100644--- a/server/routes/providers.services.test.js+++ b/server/routes/providers.services.test.js@@ -287,6 +287,18 @@ describe('POST /api/providers/services/:slug/refresh-catalog', () => {expect(store.saveConnectionSettings.mock.calls[0][0].catalog.error).not.toContain(ZEN_KEY);});+ it('sends no request carrying the key to a base URL the endpoint guard refuses', async () => {+ const blocked = graphFixture();+ blocked.connections[0].transports.openai.baseUrl = 'https://untrusted.example.com/v1';+ store.readGraph.mockResolvedValue(blocked);+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ const res = await request(app()).post('/api/providers/services/opencode-zen/refresh-catalog');+ expect(res.status).toBe(200);+ expect(probe).not.toHaveBeenCalled();+ expect(res.body.service.catalog).toMatchObject({ state: 'failed', models: ['old-free'] });+ expect(res.body.service.catalog.error).toContain('Endpoint blocked');+ });+it('records a successful empty answer as known-and-empty', async () => {probe.mockResolvedValue({ reachable: true, models: [], contextWindows: {}, error: null });const res = await request(app()).post('/api/providers/services/opencode-zen/refresh-catalog');diff --git a/server/services/providerServices.js b/server/services/providerServices.jsindex fc165e6094..a11d3450fd 100644--- a/server/services/providerServices.js+++ b/server/services/providerServices.js@@ -12,6 +12,7 @@ import {takenServiceSlugs,toServiceDto,} from '../lib/providerServiceInstances.js';+import { evaluateSecretEndpoint } from '../lib/aiToolkit/endpointGuard.js';import { requireToolkit } from '../lib/aiToolkitState.js';import { isNonBlankStr } from '../lib/textUtils.js';import { resolveServiceInstance, serviceDefinitionById } from '../lib/serviceDefinitions.js';@@ -51,6 +52,12 @@ const ANTHROPIC_VERSION = '2023-06-01';// "Import scoping").const loadInstallEnvFile = async () => (await import('./credentialInventory.js')).loadInstallEnvFile();+const hostOf = (url) => { try { return new URL(url).host; } catch { return null; } };+const isShippedDefaultHost = (definition, url) => {+ const host = hostOf(url);+ return host !== null && Object.values(definition.transports || {}).some((transport) => hostOf(transport.defaultBaseUrl) === host);+};+/*** GET `/models` on the instance's own endpoint with its own key.*@@ -69,6 +76,18 @@ async function listByProbe(connection, definition, { env, probe }) {const anthropic = connection.transports?.anthropic?.baseUrl;if (!openai && !anthropic) return { refreshed: false, error: 'This service declares no endpoint to list models from' };+ // Same guard the runner and toolkit catalog apply: never attach a key to a host+ // it would refuse. A connection carries no custom-endpoint opt-in, but a host the+ // definition itself ships as its default (opencode.ai, api.moonshot.ai) is vetted.+ if (apiKey) {+ const target = openai || anthropic;+ const guard = evaluateSecretEndpoint(target, { allowCustomEndpoint: isShippedDefaultHost(definition, target) });+ if (!guard.allowed) {+ console.warn(`⛔ Catalog refresh for ${connection.slug ?? connection.id} skipped: ${guard.reason}`);+ return { refreshed: false, error: `Endpoint blocked: ${guard.reason}` };+ }+ }+const result = openai? await probe(openai, { apiKey, timeoutMs: CATALOG_PROBE_TIMEOUT_MS })// The Anthropic API lists at `/v1/models` under its own header pair.