Skip to content

fix(chutes): bound OAuth token exchange and userinfo JSON response reads#96262

Closed
cxbAsDev wants to merge 1 commit into
openclaw:mainfrom
cxbAsDev:fix/bound-chutes-oauth-response
Closed

fix(chutes): bound OAuth token exchange and userinfo JSON response reads#96262
cxbAsDev wants to merge 1 commit into
openclaw:mainfrom
cxbAsDev:fix/bound-chutes-oauth-response

Conversation

@cxbAsDev

@cxbAsDev cxbAsDev commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace raw response.json() calls with a bounded readChutesOAuthJsonResponse helper in the Chutes OAuth flow (userinfo fetch, token exchange, and token refresh). The helper wraps readResponseWithLimit with a 4 MB cap to prevent unbounded buffering.

Real behavior proof (required for external PRs)

Behavior addressed: Three unbounded response.json() calls in the Chutes OAuth module replaced with a single bounded readChutesOAuthJsonResponse helper using readResponseWithLimit.

Real environment tested: Linux, Node 24, OpenClaw main @ 92c10d4

Exact steps or command run after fix:

pnpm install --frozen-lockfile --ignore-scripts
npx tsc --noEmit src/agents/chutes-oauth.ts

Evidence after fix:

async function readChutesOAuthJsonResponse<T>(response: Response): Promise<T> {
  const bytes = await readResponseWithLimit(response, CHUTES_OAUTH_RESPONSE_MAX_BYTES, {
    onOverflow: ({ maxBytes }) =>
      new Error(`Chutes OAuth response exceeds ${maxBytes} bytes`),
  });
  return JSON.parse(new TextDecoder().decode(bytes)) as T;
}

All three response read paths now go through this helper:

  • fetchChutesUserInfo (line 127)
  • exchangeChutesCodeForTokens (line 167)
  • refreshChutesTokens (line 239)

Observed result after fix: OAuth JSON responses are bounded at 4 MB via readResponseWithLimit. Read stops buffering when the cap is reached, before JSON.parse is called.

What was not tested: Live Chutes OAuth token exchange and refresh against api.chutes.ai was not tested.

Risk

Low. OAuth token responses are tiny (typically < 10 KB). The 4 MB cap is far above realistic response sizes. The helper function reduces duplication and keeps the bounded read pattern in one place.

Add readChutesOAuthJsonResponse helper wrapping readResponseWithLimit
with a 4 MB cap to prevent unbounded buffering of Chutes OAuth API
responses (userinfo, token exchange, and token refresh).

Co-Authored-By: Claude <[email protected]>
@cxbAsDev
cxbAsDev requested a review from a team as a code owner June 24, 2026 02:55
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 24, 2026
@clawsweeper

clawsweeper Bot commented Jun 24, 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 this PR in favor of the open canonical Chutes OAuth bounded-read PR, which targets the same three response reads with the repository's shared provider JSON helper, regression tests, and accepted real behavior proof; this branch is a smaller duplicate with a new local helper and weaker proof.

Root-cause cluster
Relationship: duplicate
Canonical: #96249
Summary: This PR and #96249 target the same three Chutes OAuth success-body JSON reads; the other PR is the canonical viable path because it uses the shared helper and includes proof/tests.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Use #96249 as the canonical landing path and repair its narrow test typecheck blocker instead of merging this duplicate local-helper branch.

So I’m closing this here and keeping the remaining discussion on #96249.

Review details

Best possible solution:

Use #96249 as the canonical landing path and repair its narrow test typecheck blocker instead of merging this duplicate local-helper branch.

Do we have a high-confidence way to reproduce the issue?

Yes from source: current main still uses raw response.json() for the three Chutes OAuth success bodies, which can buffer provider-controlled response bodies without a cap. I did not run a local hostile-body repro for this branch.

Is this the best way to solve the issue?

No. Bounding the reads is the right bug fix, but the best repository-shaped solution is the shared readProviderJsonResponse path with regression proof, which is already covered by #96249.

Security review:

Security review cleared: The diff does not add dependency, workflow, permission, secret, package-resolution, or supply-chain risk; the functional duplicate-helper concern is tracked separately.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • Josh Lehman: Current-main blame for the Chutes OAuth response reads and the shared provider HTTP helper points to the recent agent refactor commit. (role: recent area contributor; confidence: high; commits: f8ed4de460f7; files: src/agents/chutes-oauth.ts, src/agents/provider-http-errors.ts, src/plugin-sdk/provider-http.ts)
  • Friederike Seiler: Git history shows the original Chutes OAuth implementation was added in this area by this author. (role: feature introducer; confidence: medium; commits: 4efb5cc18efa, 3271ff1d6e26, 0efcfc0864fc; files: src/agents/chutes-oauth.ts)
  • Peter Steinberger: Chutes OAuth adjacent tests and auth-flow test layout have repeated history from this author, which is relevant because the canonical PR adds regression tests in that surface. (role: adjacent test/history contributor; confidence: medium; commits: 713e2928b222, e441390fd1b8, 5f710bac3563; files: src/agents/chutes-oauth.flow.test.ts, src/commands/chutes-oauth.test.ts, src/agents/auth-profiles.chutes.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 2ab3b223ed69.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 24, 2026
@cxbAsDev cxbAsDev closed this Jun 24, 2026
@cxbAsDev
cxbAsDev deleted the fix/bound-chutes-oauth-response branch July 15, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant