From 302cc79c00398322ed2264e8ef24f74ac31d98fa Mon Sep 17 00:00:00 2001 From: Epinephrine Date: Thu, 26 Nov 2026 11:47:23 +0900 Subject: [PATCH] Fix security finding acf_b8f0e4ecf67276cb7603e32d7a0a3408 --- src/server/search.ts | 3 +- .../providers/codex-installation-identity.md | 2 + tests/server/server-search.test.ts | 58 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/server/search.ts b/src/server/search.ts index 5b28c568e3f..40ae8d9c059 100644 --- a/src/server/search.ts +++ b/src/server/search.ts @@ -1,3 +1,4 @@ +import { codexAccountFetch } from "../codex/account-egress-runtime"; import { CodexInstallationIdUnavailableError } from "../codex/installation-id"; import { isolateCodexPoolClientMetadata, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers"; /** @@ -207,7 +208,7 @@ export async function handleSearch( let upstreamResponse: Response | undefined; try { upstream.beforeDispatch?.(); - upstreamResponse = await fetch(url, { + upstreamResponse = await codexAccountFetch(codexLogAccountId(upstream.authContext), { config })(url, { method: "POST", headers, body: JSON.stringify(isolateCodexPoolClientMetadata( diff --git a/structure/providers/codex-installation-identity.md b/structure/providers/codex-installation-identity.md index f5f262e0148..e55042a6a80 100644 --- a/structure/providers/codex-installation-identity.md +++ b/structure/providers/codex-installation-identity.md @@ -76,6 +76,8 @@ retain the selected context and project cloned client metadata immediately befor JSON send, including live's converted multipart session. Live inspects JSON content independently of Content-Type; non-JSON SDP retains its original bytes. Their selected headers authoritatively replace or remove mixed-case provider identity defaults; main and main-pool preserve caller values. +Search also resolves the selected Pool account's outbound route at its physical send boundary; +an account route overrides the OpenAI provider route, and an invalid route refuses the send. Vision, audio and sidecar credential selection share materialization. Dictation in `src/server/audio-dictation.ts` has a 600,000 ms recording budget and opts into a separate 60,000 ms finalization window after a validated `session.close`. diff --git a/tests/server/server-search.test.ts b/tests/server/server-search.test.ts index 388306d5cc9..c653298aa79 100644 --- a/tests/server/server-search.test.ts +++ b/tests/server/server-search.test.ts @@ -323,6 +323,64 @@ test("an account-qualified search model uses that exact account and sends the ba } }); +test("an account-qualified search leaves through its selected account route", async () => { + const accountProxy = "http://127.0.0.1:9/"; + const providerProxy = "http://127.0.0.1:11/"; + const config = exactSearchConfig(); + config.providers.openai!.proxy = providerProxy; + config.codexAccounts = config.codexAccounts?.map(account => account.id === "pool-a" + ? { ...account, egress: { proxy: accountProxy } } + : account); + saveExactSearchCredentials(); + const sends: Array<{ proxy: unknown; authorization: string | null; account: string | null; body: unknown }> = []; + globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => { + const headers = new Headers(init?.headers); + sends.push({ + proxy: (init as { proxy?: unknown } | undefined)?.proxy, + authorization: headers.get("authorization"), + account: headers.get("chatgpt-account-id"), + body: typeof init?.body === "string" ? JSON.parse(init.body) : undefined, + }); + return Response.json({ encrypted_output: "ciphertext", output: "search result" }); + }) as typeof fetch; + + const response = await handleSearch( + alphaSearchRequest({ id: "search-session", model: "side/gpt-test" }), + config, + { model: "", provider: "" }, + ); + + expect(response.status).toBe(200); + expect(sends).toEqual([{ + proxy: accountProxy, + authorization: "Bearer pool-a-token", + account: "acct-pool-a", + body: { id: "search-session", model: "gpt-test" }, + }]); +}); + +test("an invalid selected account route refuses search before dispatch", async () => { + const config = exactSearchConfig(); + config.codexAccounts = config.codexAccounts?.map(account => account.id === "pool-a" + ? { ...account, egress: { proxy: "not-a-proxy-route" } } + : account); + saveExactSearchCredentials(); + let sends = 0; + globalThis.fetch = (async () => { + sends += 1; + return Response.json({ output: "must not dispatch" }); + }) as typeof fetch; + + const response = await handleSearch( + alphaSearchRequest({ id: "search-session", model: "side/gpt-test" }), + config, + { model: "", provider: "" }, + ); + + expect(response.status).toBe(502); + expect(sends).toBe(0); +}); + test("an exact search 429 never switches to the active Pool account and reports only its public selector", async () => { const captured: CapturedRequest[] = []; const upstream = fakeSearchUpstream(captured, 429, { error: { message: "rate limited" } });