Skip to content

fix(openai): bound Codex OAuth token response body reads with readResponseWithLimit - #99479

Merged
steipete merged 3 commits into
openclaw:mainfrom
Pandah97:fix/bounded-openai-oauth-token-response-reads
Jul 6, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Pandah97:fix/bounded-openai-oauth-token-response-reads

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The shared ChatGPT OAuth token request helper buffered https://auth.openai.com/oauth/token responses with an unbounded response.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

postTokenForm is the single network-read owner for both operations. It now uses the existing streaming readResponseWithLimit helper with a 1 MiB cap, materializes the bounded bytes into the same Response shape, 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

  • Exact head: 5b037990765a7341b77dba31abc2886e82f99516
  • Sanitized AWS Crabbox: cbx_6a45fcced145, public networking, no Tailscale, no instance profile
  • Run: run_4794c8a54d94
  • Environment: Linux x86_64, Node 24.15.0, pnpm 11.2.2
  • Command: pnpm test extensions/openai/openai-chatgpt-oauth-flow.runtime.test.ts
  • Result: 12/12 tests passed, including real loopback HTTP under-cap and over-cap paths plus guarded-fetch release assertions
  • Fresh GPT-5.5 autoreview: no accepted/actionable findings; patch correctness confidence 0.98
  • Direct dependency audit: packages/media-core/src/read-response-with-limit.ts cancels the response reader on overflow before throwing the contextual error

Not 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

…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.
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

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
Relationship: duplicate
Canonical: #98113
Summary: This PR and the canonical PR both target the OpenAI Codex OAuth token-response first-read OOM issue; the canonical PR is the viable landing path because it is open, clean, proof-positive, maintainer-validated, and broader.

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 details

Best 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 response.arrayBuffer() before exchange or refresh parsing can enforce any cap.

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:

  • steipete: PR metadata and git history show steipete authored and merged the OpenAI provider identity unification that carried this OAuth runtime file, and later posted maintainer validation on the canonical related PR. (role: OpenAI OAuth area refactor contributor and canonical-path validator; confidence: high; commits: 4c33aaa86c16; files: extensions/openai/openai-chatgpt-oauth-flow.runtime.ts)
  • Alix-007: PR metadata and git history show Alix-007 authored the merged readProviderJsonResponse hardening used by the canonical broader fix. (role: adjacent bounded provider JSON helper contributor; confidence: high; commits: 2592f8a51a4e; files: src/agents/provider-http-errors.ts, src/plugin-sdk/provider-http.ts)
  • joshavant: Recent history shows follow-up work on successful provider response reads in the same helper surface involved in this response-boundary pattern. (role: adjacent provider response-boundary contributor; confidence: medium; commits: 0a14444924e3; files: src/agents/provider-http-errors.ts, src/plugin-sdk/provider-http.ts)
  • wangmiao0668000666: Recent history shows Google OAuth body-cap work using the same readResponseWithLimit response-boundary pattern relevant to this OpenAI OAuth change family. (role: sibling OAuth hardening contributor; confidence: medium; commits: a6aaba76ac66; files: extensions/google/oauth.http.ts)

Codex review notes: model internal, reasoning high; reviewed against 36dd9ee3c3c1.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 3, 2026
…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
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 3, 2026
@steipete steipete self-assigned this Jul 6, 2026
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 5b037990765a7341b77dba31abc2886e82f99516:

  • Best-fix review: the shared postTokenForm read boundary caps both authorization-code and refresh responses at 1 MiB while preserving the existing Response status, headers, body bytes, JSON parsing, and error-text behavior. Duplicate approaches fix(openai): bound Codex OAuth JSON and error response reads to prevent OOM #98113 and fix(extensions/openai): bound ChatGPT OAuth token response reads to prevent OOM #101075 add a second read boundary or change response semantics.
  • Exact-head isolated proof: sanitized AWS Crabbox cbx_6a45fcced145, run run_4794c8a54d94, Linux x86_64, Node 24.15.0, pnpm 11.2.2; pnpm test extensions/openai/openai-chatgpt-oauth-flow.runtime.test.ts; 12/12 passed.
  • The real loopback HTTP tests prove valid response preservation, streamed overflow cancellation, and guarded-fetch release on both success and overflow.
  • Fresh GPT-5.5 autoreview: no accepted or actionable findings; correctness confidence 0.98.
  • Exact-head hosted CI: run 28829382267, success.
  • Upstream contract checked directly: Codex authorization-code exchange and refresh flow.
  • Native landing gate: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 99479 passed with exact-head hosted gates; changelog not required for this changed-file set.

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.

@steipete
steipete merged commit a89fe70 into openclaw:main Jul 6, 2026
95 checks passed
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

@Pandah97

Pandah97 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick merge, @steipete. Appreciate the review.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
…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]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Jul 15, 2026
…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)
zeekay pushed a commit to hanzoai/bot that referenced this pull request Sep 11, 2026
…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]>
zeekay pushed a commit to hanzoai/bot that referenced this pull request Sep 11, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants