Repository navigation
[Codex Security] Account-qualified search bypasses the new per-account proxy #844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 SOCKS5 searches fail before longer configured deadlines Account-routed SOCKS5 searches inherit a 200-second idle timeout from socks5Fetch. A search that sends no headers during that interval returns 502 even when its configured deadline allows it to finish. Learn moreThe search handler creates an abort signal for the configured total deadline. Applying an account-specific SOCKS5 route makes configuredOutboundFetch use socks5Fetch, which also installs a fixed 200-second upstream socket idle timer. The search contract explains why a healthy request can send no response headers until the search finishes. If the socket timer fires first, it throws Example: With Recommended fix: Let this relay pass its upstream deadline policy through the account-aware transport, so the SOCKS5 response idle timer does not preempt the search budget. Keep the SOCKS5 connection and handshake guards and retain the fixed default for callers that do not supply a response budget. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify(isolateCodexPoolClientMetadata( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Comment on lines
+79
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Public proxy docs still exclude unqualified Pool search Unqualified search now uses account-aware egress when it selects a Pool account. The provider configuration guide still says unqualified search has no provider route. Update it to distinguish Pool search from caller-owned search. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| 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`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Comment on lines
+336
to
+345
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Search tests check the proxy option, not the network path The stub confirms which Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| 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" } }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Local search proxy refusals can switch the active Codex account
When process NO_PROXY conflicts with a Pool account’s HTTP proxy, search records the local refusal as an upstream connection failure. Repeated unqualified searches can switch the active account even though no search reached ChatGPT.
Learn more
The ChatGPT search relay now uses codexAccountFetch for pool traffic. If process
NO_PROXYexempts ChatGPT, configuredOutboundFetch rejects an explicitly selected HTTP proxy before opening a connection. The search error handler passes that refusal to the unqualified sidecar’s outcome recorder asconnect_error. recordCodexUpstreamOutcome adds to the selected account’s transient failure streak and calls applyFailureFailover for an active account. With an eligible sibling, this updates the shared active selection rather than just returning a search error.Example: With account A active, account B eligible, and the default threshold of three, three ordinary unqualified searches select A and hit the same local proxy refusal. The third failure can promote B, so fixing A’s proxy settings does not undo the account switch.
Recommended fix: Handle typed pre-send route refusals separately in
handleSearch. Release the probe lease and return a local route error without recording an upstream outcome. Add a regression test for a valid HTTP proxy conflicting with processNO_PROXYthat checks both zero sends and unchanged Pool health.Was this helpful? React with 👍 or 👎 to provide feedback.