Repository navigation
fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit - #99479
Conversation
…ponseWithLimit Replace unbounded response.arrayBuffer() in postTokenForm with readResponseWithLimit using a 1 MiB cap to prevent OOM from oversized token endpoint responses. Add real node:http loopback server tests.
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR is a correct narrow fix for the OpenAI Codex OAuth first-read body cap, but #98113 is open, mergeable, proof-positive, maintainer-validated, and covers the same cap plus bounded JSON/error reads. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this branch and continue review or landing on #98113 as the canonical OpenAI Codex OAuth response-boundary fix. So I’m closing this here and keeping the remaining discussion on #98113. Review detailsBest possible solution: Close this branch and continue review or landing on #98113 as the canonical OpenAI Codex OAuth response-boundary fix. Do we have a high-confidence way to reproduce the issue? Yes from source inspection. Current main reads the OpenAI Codex OAuth token response with raw Is this the best way to solve the issue? No as a landing path. The patch is a plausible narrow mitigation, but the best current solution is the open canonical PR because it covers the same first-read boundary plus downstream JSON and error reads. Security review: Security review cleared: Cleared: the diff hardens an existing OAuth token response read and adds no dependency, workflow, credential, package, or supply-chain surface. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 36dd9ee3c3c1. |
…odyInit compat - Fixes TS2345: Buffer<ArrayBufferLike> not assignable to BodyInit - Resolves check-prod-types, check-test-types, and check-additional-extension-package-boundary CI failures Ref. openclaw#99479
|
Land-ready proof for exact head
Known gap: no credentialed live OpenAI login was attempted. The changed production boundary is covered through a real loopback HTTP server, including stream cancellation and release behavior. |
|
Merged via squash.
|
|
Thanks for the quick merge, @steipete. Appreciate the review. |
…ponseWithLimit (openclaw#99479) * fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit Replace unbounded response.arrayBuffer() in postTokenForm with readResponseWithLimit using a 1 MiB cap to prevent OOM from oversized token endpoint responses. Add real node:http loopback server tests. * fix(openai): wrap readResponseWithLimit result in Uint8Array for TS BodyInit compat - Fixes TS2345: Buffer<ArrayBufferLike> not assignable to BodyInit - Resolves check-prod-types, check-test-types, and check-additional-extension-package-boundary CI failures Ref. openclaw#99479 * test(openai): verify OAuth response release --------- Co-authored-by: Peter Steinberger <[email protected]>
…ponseWithLimit (openclaw#99479) * fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit Replace unbounded response.arrayBuffer() in postTokenForm with readResponseWithLimit using a 1 MiB cap to prevent OOM from oversized token endpoint responses. Add real node:http loopback server tests. * fix(openai): wrap readResponseWithLimit result in Uint8Array for TS BodyInit compat - Fixes TS2345: Buffer<ArrayBufferLike> not assignable to BodyInit - Resolves check-prod-types, check-test-types, and check-additional-extension-package-boundary CI failures Ref. openclaw#99479 * test(openai): verify OAuth response release --------- Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit a89fe70)
…ponseWithLimit (#99479) * fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit Replace unbounded response.arrayBuffer() in postTokenForm with readResponseWithLimit using a 1 MiB cap to prevent OOM from oversized token endpoint responses. Add real node:http loopback server tests. * fix(openai): wrap readResponseWithLimit result in Uint8Array for TS BodyInit compat - Fixes TS2345: Buffer<ArrayBufferLike> not assignable to BodyInit - Resolves check-prod-types, check-test-types, and check-additional-extension-package-boundary CI failures Ref. openclaw/openclaw#99479 * test(openai): verify OAuth response release --------- Co-authored-by: Peter Steinberger <[email protected]>
…ponseWithLimit (#99479) * fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit Replace unbounded response.arrayBuffer() in postTokenForm with readResponseWithLimit using a 1 MiB cap to prevent OOM from oversized token endpoint responses. Add real node:http loopback server tests. * fix(openai): wrap readResponseWithLimit result in Uint8Array for TS BodyInit compat - Fixes TS2345: Buffer<ArrayBufferLike> not assignable to BodyInit - Resolves check-prod-types, check-test-types, and check-additional-extension-package-boundary CI failures Ref. openclaw/openclaw#99479 * test(openai): verify OAuth response release --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
The shared ChatGPT OAuth token request helper buffered
https://auth.openai.com/oauth/tokenresponses with an unboundedresponse.arrayBuffer(). Both authorization-code exchange and token refresh used that helper, so a malfunctioning or hostile response could exhaust Gateway memory before either caller parsed it.Why This Change Was Made
postTokenFormis the single network-read owner for both operations. It now uses the existing streamingreadResponseWithLimithelper with a 1 MiB cap, materializes the bounded bytes into the sameResponseshape, and keeps the existing status, headers, JSON parsing, error text, timeout, abort, and guarded-fetch release behavior.This is cleaner than the overlapping alternatives:
The current Codex implementation confirms the same token endpoint and response contract: authorization-code exchange and refresh.
User Impact
Normal ChatGPT OAuth sign-in and refresh behavior is unchanged. Oversized token responses now fail through the existing provider result shape after the response stream is cancelled and the guarded fetch is released.
Evidence
5b037990765a7341b77dba31abc2886e82f99516cbx_6a45fcced145, public networking, no Tailscale, no instance profilepnpm test extensions/openai/openai-chatgpt-oauth-flow.runtime.test.tspackages/media-core/src/read-response-with-limit.tscancels the response reader on overflow before throwing the contextual errorNot exercised: a credentialed live OpenAI login. The changed surface is the response-stream boundary, and the real loopback server drives that production path without requiring or exposing user credentials.
Contributor: @Pandah97