feat(gateway): opt-in stripping of Codex connector/app tools for shared OAuth accounts#3408
Open
kangjwme wants to merge 2 commits into
Open
feat(gateway): opt-in stripping of Codex connector/app tools for shared OAuth accounts#3408kangjwme wants to merge 2 commits into
kangjwme wants to merge 2 commits into
Conversation
When one ChatGPT/Codex OAuth account is shared across many downstream API keys, the gateway forwards the request `tools` array verbatim. ChatGPT connector/app tools (the `codex_apps.*` namespace) execute server-side under the account owner's identity (e.g. the GitHub connector reading the owner's private repos), so a downstream caller could invoke the owner's connectors through the shared account. Add a `gateway.codex_block_connector_tools` flag (default false, no behavior change). When enabled, connector/app tools and connector enumeration tools (app/list, mcpServerStatus/list, ...) are dropped from forwarded Codex OAuth requests before they reach the upstream, and a tool_choice that pinned a removed tool is reset to "auto". Name matching normalizes ., - and / separators so codex_apps.github, codex_apps__github and codex_apps-github all match, while suffix matches like my_codex_apps are left untouched. Wired into all three Codex OAuth forward paths (messages, chat_completions, responses). Adds unit tests and documents the flag in deploy/config.example.yaml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
sub2api shares one upstream ChatGPT/Codex OAuth account across many downstream API keys. On the Codex OAuth forward path the request
toolsarray is forwarded verbatim (only structurally normalized innormalizeCodexTools).ChatGPT connector/app tools (the
codex_apps.*namespace — GitHub, Google Drive, Gmail, …) are executed server-side by OpenAI under the account owner's identity. Concretely, the GitHub connector performs actions as the account owner's linked GitHub identity (see openai/codex#24735), and the connector tools are surfaced under thecodex_appsMCP namespace (openai/codex#10750).Consequence: when an OAuth account that has connectors enabled is shared, a downstream caller can include
codex_apps.*tools in their request and have them run with the account owner's connector credentials (e.g. read the owner's private repos). The proxy currently applies no per-key tool authorization.Change
Add an opt-in flag
gateway.codex_block_connector_tools(defaultfalse, no behavior change). When enabled, before forwarding a Codex OAuth request the gateway:codex_apps.*namespace and connector-enumeration tools (app/list,apps/list,mcpServerStatus/list,list_connectors,connectors/list);tool_choicethat pinned a removed tool back to"auto"(avoids an upstream "unknown tool" error);Name matching normalizes
.,-,/to_, socodex_apps.github.get_repo,codex_apps__github__get_repoandcodex_apps-github-get_repoall match, while suffix-only names likemy_codex_appsand separator-lesscodexappsare left untouched.Wired into all three Codex OAuth forward paths:
ForwardAsAnthropic(messages),ForwardAsChatCompletions, and the/v1/responsesForward. The existingapplyCodexOAuthTransformwrapper is preserved; only the two production call sites were switched to...WithOptionsto thread the flag.Default / compatibility
Default is
falseto match the project's existing Codex flag convention (force_codex_cli,codex_image_generation_bridge_enabled, …) and to avoid changing behavior for existing deployments. Shared-account / multi-tenant operators are advised to enable it. Happy to flip the default to secure-by-default if preferred.Tests
tool_choicereset, and that the default (flag off) leaves the connector tool in place.go test ./...), incl.internal/service,internal/handler,apicompat,openai_ws_v2.gofmtclean; changed code passesgolangci-lint.Notes / follow-ups (not in this PR)
The strongest mitigation remains operational: don't enable connectors on accounts shared into the proxy. Possible follow-ups: per-API-key/group tool allow/block lists, and namespacing
previous_response_idon the WS v2 path.