Skip to content

feat(openai): add ChatGPT OAuth-backed ChatOpenAICodex chat model#37569

Open
open-swe[bot] wants to merge 13 commits into
masterfrom
open-swe/chatgpt-oauth
Open

feat(openai): add ChatGPT OAuth-backed ChatOpenAICodex chat model#37569
open-swe[bot] wants to merge 13 commits into
masterfrom
open-swe/chatgpt-oauth

Conversation

@open-swe
Copy link
Copy Markdown
Contributor

@open-swe open-swe Bot commented May 19, 2026

Docs

Adds a new ChatOpenAICodex chat model and a small chatgpt_oauth module 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 at https://chatgpt.com/backend-api/codex. Login and token persistence live behind a refresh-aware ChatGPTOAuthTokenProvider protocol so they stay decoupled from model invocation. The existing API-key ChatOpenAI behavior is untouched. By default the file-backed provider writes to ~/.langchain/chatgpt-auth.json to avoid stomping on Codex CLI / VS Code sessions at ~/.codex/auth.json. No new required dependencies are introduced (uses stdlib + httpx).

from langchain_openai import ChatOpenAICodex
from langchain_openai.chatgpt_oauth import login_chatgpt

login_chatgpt()
model = ChatOpenAICodex(model="gpt-5.5")
response = model.invoke("hello")

Opened collaboratively by Mason Daugherty and open-swe.

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>
@github-actions github-actions Bot added feature For PRs that implement a new feature; NOT A FEATURE REQUEST integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: XL 1000+ LOC labels May 19, 2026
Copy link
Copy Markdown
Contributor

@corridor-security corridor-security Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Issues

  • OAuth Token Exfiltration via Caller-Controlled base_url
    ChatOpenAICodex uses a ChatGPT OAuth access token as the OpenAI SDK api_key, but the constructor's setdefault logic preserves any caller-supplied base_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 to ChatOpenAICodex), they can point the model at an arbitrary HTTPS endpoint. The OpenAI SDK will then send the victim service's Authorization: Bearer <access_token> and ChatGPT-Account-Id headers to the attacker-controlled host on every invocation.

Recommendations

  • Enforce that base_url / openai_api_base matches exactly CHATGPT_CODEX_BASE_URL inside _apply_codex_defaults, or unconditionally overwrite both fields with the constant before wiring in the OAuth token provider.

Comment thread libs/partners/openai/langchain_openai/chat_models/codex.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature For PRs that implement a new feature; NOT A FEATURE REQUEST integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: XL 1000+ LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants