Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): guard provider model fetch IPC (#740)
Chris Zhang4618a3e3105f
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.tsindex 903c92ae59..4fcfd4dc74 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts@@ -1001,6 +1001,27 @@ describe('provider:test-connection handler', () => {});describe('provider:models-fetch handler', () => {+ it('rejects an untrusted sender before issuing a credentialed model request', async () => {+ const harness = new IpcHarness();+ const assertTrustedSender = vi.fn(() => {+ throwIpcError('PERMISSION_DENIED', '此操作只能从 Cindy 主页面发起');+ });+ const deps = makeDeps({ assertTrustedSender });+ registerProviderHandlers(harness, deps);++ await expect(+ harness.invoke(MAKER_INVOKE.PROVIDER_MODELS_FETCH, {+ agent: 'codex',+ baseUrl: 'https://attacker.example/v1',+ authMethod: 'apiKey',+ apiKey: 'credential-must-not-leave-main',+ headers: { 'x-api-key': 'custom-credential' },+ }),+ ).rejects.toThrow(/PERMISSION_DENIED/);+ expect(assertTrustedSender).toHaveBeenCalledOnce();+ expect(deps.fetchModels).not.toHaveBeenCalled();+ });+it('forwards parsed input and returns the structured result', async () => {const harness = new IpcHarness();const fetchModels = vi.fn(async () => ({diff --git a/apps/desktop/src/main/maker-ipc/providerHandlers.ts b/apps/desktop/src/main/maker-ipc/providerHandlers.tsindex 7fd694cbab..494b241012 100644--- a/apps/desktop/src/main/maker-ipc/providerHandlers.ts+++ b/apps/desktop/src/main/maker-ipc/providerHandlers.ts@@ -740,8 +740,12 @@ export function registerProviderHandlers(}});- // 获取模型列表:查询型结构化返回(同上例外条款);网络/上游失败在结果 code 里,不抛。- registry.handle(MAKER_INVOKE.PROVIDER_MODELS_FETCH, async (_event, input: unknown) => {+ // 获取模型列表:查询型结构化返回(同上例外条款);仅网络/上游失败在结果 code 里,不抛。+ registry.handle(MAKER_INVOKE.PROVIDER_MODELS_FETCH, async (event, input: unknown) => {+ // 这条查询会把 renderer 提供的 API key / 自定义 headers 带到目标 endpoint;+ // 与重新发现一样,必须先确认调用方是 Cindy 自有顶层页面,避免 WebView / 子 frame+ // 把 Main 变成可向任意 http(s) 地址发凭证请求的代理。+ assertTrustedProviderMutationSender(event);const parsed = parseModelsFetchInput(input);if (!parsed) throwIpcError('INVALID_PARAMS', 'invalid models-fetch input');return deps.fetchModels(parsed);