Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(provider): clear stored custom headers when auth switches away from api key

Chris5fe0409f1b30
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts
index 6dd81557fd..6265929a86 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/providerHandlers.test.ts
@@ -890,6 +890,23 @@ describe('provider:custom:* CRUD handlers', () => {
expect(removeCustomProviderHeaders).not.toHaveBeenCalledWith('keep-headers', 'pi');
expect(storeCustomProviderHeaders).not.toHaveBeenCalled();
expect(headers.get('pi')).toEqual({ Authorization: 'Bearer keepme' });
+
+ // 切到 auth='none' 且不带头 → 清除残留凭证头(不保留),否则关掉鉴权后旧头仍可能
+ // 被 hydrate 发往新 baseUrl(codex review)。
+ removeCustomProviderHeaders.mockClear();
+ // auth='none' 校验要求 baseUrl 为 loopback(no-auth 只允许本机端点)。
+ await expect(harness.invoke(MAKER_INVOKE.PROVIDER_CUSTOM_UPDATE, {
+ ...base,
+ auth: { method: 'none' },
+ runtimes: {
+ pi: {
+ baseUrl: 'http://127.0.0.1:8080/v1',
+ models: [{ id: 'm', name: 'M' }],
+ },
+ },
+ })).resolves.toEqual({ ok: true });
+ expect(removeCustomProviderHeaders).toHaveBeenCalledWith('keep-headers', 'pi');
+ expect(headers.get('pi')).toBeUndefined();
});
it('merges stored main-only headers into a saved-provider model fetch', async () => {
diff --git a/apps/desktop/src/main/maker-ipc/providerHandlers.ts b/apps/desktop/src/main/maker-ipc/providerHandlers.ts
index 9421f93a94..ec8ccf69ff 100644
--- a/apps/desktop/src/main/maker-ipc/providerHandlers.ts
+++ b/apps/desktop/src/main/maker-ipc/providerHandlers.ts
@@ -662,6 +662,9 @@ export function registerProviderHandlers(
headers: CustomProviderHeaderSecrets,
mode: 'create' | 'update' | 'delete',
): HeaderMutation[] => {
+ // 头凭证在 auth='none'/'oauth' 下不该继续留存(与 planProviderKeyMutations 的
+ // usesApiKey 同口径):这两种模式不经存储的鉴权请求头路由。
+ const usesApiKey = !config.auth || config.auth.method === 'apiKey';
const mutations: HeaderMutation[] = [];
for (const agent of CUSTOM_PROVIDER_RUNTIME_AGENTS) {
const replacement = headers[agent];
@@ -678,12 +681,16 @@ export function registerProviderHandlers(
// 删除,否则仅改名称/模型也会清掉鉴权头使 provider 失效(codex review)。
// - runtime 被移除(config 里没有该 agent)→ 清掉其残留头。
// - 显式带了 headers(含用户新填)→ 覆盖为新值。
+ // - 切到 none/oauth(!usesApiKey)且未带头 → 清除残留凭证头,不保留,否则用户
+ // 显式关掉鉴权后,旧 Authorization 仍会被 hydrate 并可能发往新 baseUrl(codex review)。
if (!config.runtimes[agent]) {
mutations.push({ agent, replacement: null });
} else if (replacement) {
mutations.push({ agent, replacement });
+ } else if (!usesApiKey) {
+ mutations.push({ agent, replacement: null });
}
- // else: runtime 存在但未提供 headers → 保留,跳过。
+ // else: runtime 存在 + apiKey 鉴权 + 未提供 headers → 保留,跳过。
}
return mutations;
};