feat(openai): add ChatGPT OAuth-backed ChatOpenAICodex chat model#37569
Open
open-swe[bot] wants to merge 13 commits into
Open
feat(openai): add ChatGPT OAuth-backed ChatOpenAICodex chat model#37569open-swe[bot] wants to merge 13 commits into
ChatOpenAICodex chat model#37569open-swe[bot] wants to merge 13 commits into
Conversation
Adds a separate `ChatOpenAICodex` class plus a self-contained `chatgpt_oauth` module so users can authenticate with their ChatGPT subscription (via OAuth 2.0 PKCE) and route Responses-API requests to the ChatGPT Codex backend. Login and token storage are kept independent from model invocation, and the existing API-key `ChatOpenAI` flow is unchanged. Tokens default to `~/.langchain/chatgpt-auth.json` to avoid colliding with the Codex CLI store. Co-authored-by: Mason Daugherty <61371264+mdrxy@users.noreply.github.com>
3 tasks
Contributor
There was a problem hiding this comment.
Security Issues
- OAuth Token Exfiltration via Caller-Controlled
base_url
ChatOpenAICodexuses a ChatGPT OAuth access token as the OpenAI SDKapi_key, but the constructor'ssetdefaultlogic preserves any caller-suppliedbase_url/openai_api_base— it only fills in the Codex URL when neither field is already set. If an attacker can influence model configuration (e.g., via a serialized config, environment-driven instantiation, or a multi-tenant service that passes user-supplied kwargs toChatOpenAICodex), they can point the model at an arbitrary HTTPS endpoint. The OpenAI SDK will then send the victim service'sAuthorization: Bearer <access_token>andChatGPT-Account-Idheaders to the attacker-controlled host on every invocation.
Recommendations
- Enforce that
base_url/openai_api_basematches exactlyCHATGPT_CODEX_BASE_URLinside_apply_codex_defaults, or unconditionally overwrite both fields with the constant before wiring in the OAuth token provider.
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.
Docs
Adds a new
ChatOpenAICodexchat model and a smallchatgpt_oauthmodule so users can authenticate with their ChatGPT subscription (OAuth 2.0 Authorization Code Flow with PKCE) and route Responses-API requests to the ChatGPT Codex backend athttps://chatgpt.com/backend-api/codex. Login and token persistence live behind a refresh-awareChatGPTOAuthTokenProviderprotocol so they stay decoupled from model invocation. The existing API-keyChatOpenAIbehavior is untouched. By default the file-backed provider writes to~/.langchain/chatgpt-auth.jsonto avoid stomping on Codex CLI / VS Code sessions at~/.codex/auth.json. No new required dependencies are introduced (uses stdlib +httpx).Opened collaboratively by Mason Daugherty and open-swe.