Skip to content

fix(google): bound Vertex ADC OAuth token refresh responses - #98706

Closed
ly85206559 wants to merge 0 commit into
openclaw:mainfrom
ly85206559:fix/google-bound-vertex-oauth-responses
Closed

ly85206559 wants to merge 0 commit into
openclaw:mainfrom
ly85206559:fix/google-bound-vertex-oauth-responses

Conversation

@ly85206559

@ly85206559 ly85206559 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a sibling OOM risk in the Google Vertex ADC OAuth token refresh path. Gemini CLI OAuth calls already cap HTTP bodies at 16 MiB via fetchWithTimeout, but readGoogleOauthTokenResponsePayload in the Vertex ADC refresh flow still buffered the full token response with response.arrayBuffer(). A faulty or hostile OAuth endpoint could stream an oversized refresh body and grow gateway memory without bound.

Related: #98507 covers the same bug class with additional gzip/decompression hardening.

Why This Change Was Made

The Vertex ADC refresh path now uses the shared bounded response reader (readResponseWithLimit) and reuses GOOGLE_OAUTH_BODY_MAX_BYTES (16 MiB) from oauth.http.ts so the cap stays consistent across Google OAuth call sites.

This follows the same invariant as recent Google provider hardening work (for example #98692 on embedding batch reads): legitimate small token responses keep working, but unbounded provider output must be cancelled early.

Scope is intentionally narrow:

  • export the shared 16 MiB OAuth body cap from oauth.http.ts
  • replace the bare arrayBuffer() read in readGoogleOauthTokenResponsePayload
  • add focused regression tests for normal refresh and oversized streamed bodies

This PR does not change ADC discovery, cache behavior, gzip decode policy, or non-OAuth Vertex auth flows.

User Impact

Users running Google Vertex with authorized_user ADC keep the same refresh behavior for normal token responses (typically well under 10 KiB). If a refresh response exceeds 16 MiB, the gateway now fails fast with a clear error instead of buffering the entire body into memory.

Evidence

Shared bounded-read wire proof: oauth.http.test.ts exercises the same readResponseWithLimit helper this PR uses on the Vertex ADC path against a local http.createServer listener on 127.0.0.1 with real fetch() and streamed chunked bodies. No mocked reader.

stdout | extensions/google/oauth.http.test.ts > oauth.http bounded-read real wire proof (loopback http.createServer) > caps an oversized body streamed chunked over real wire
[oauth.http loopback proof] oversized path: cap=16777216 reported=16842704 server_total=18874368

stdout | extensions/google/oauth.http.test.ts > oauth.http bounded-read real wire proof (loopback http.createServer) > returns a Buffer for normal-size responses on real wire
[oauth.http loopback proof] normal path: cap=16777216 returned=45 body="{\"access_token\":\"loopback\",\"expires_in\":3600}"

Targeted unit proof: the new tests drive the production resolveGoogleVertexAuthorizedUserHeaders -> refreshGoogleVertexAuthorizedUserAccessToken -> readGoogleOauthTokenResponsePayload path with real Response streams passed through an injected fetchImpl. They cover the normal authorized_user refresh case and the oversized streamed refresh body case that previously relied on unbounded arrayBuffer().

$ pnpm test extensions/google/vertex-adc.oauth-response.test.ts extensions/google/oauth.http.test.ts -- --reporter=verbose
 ✓ |extension-providers| extensions/google/oauth.http.test.ts > oauth.http fetchWithTimeout body byte cap > caps oversized response body at 16 MiB with labeled overflow error
 ✓ |extension-providers| extensions/google/oauth.http.test.ts > oauth.http fetchWithTimeout body byte cap > returns a Response for normal-size bodies
 ✓ |extension-providers| extensions/google/oauth.http.test.ts > oauth.http bounded-read real wire proof (loopback http.createServer) > caps an oversized body streamed chunked over real wire
 ✓ |extension-providers| extensions/google/oauth.http.test.ts > oauth.http bounded-read real wire proof (loopback http.createServer) > returns a Buffer for normal-size responses on real wire
 ✓ |extension-providers| extensions/google/vertex-adc.oauth-response.test.ts > vertex-adc OAuth token response bounds > parses a normal token refresh response
 ✓ |extension-providers| extensions/google/vertex-adc.oauth-response.test.ts > vertex-adc OAuth token response bounds > rejects oversized token refresh bodies instead of buffering the whole stream

 Test Files  2 passed (2)
      Tests  6 passed (6)
[test] passed 1 Vitest shard in 17.15s
$ node_modules/.bin/oxfmt --check extensions/google/oauth.http.ts extensions/google/vertex-adc.ts extensions/google/vertex-adc.oauth-response.test.ts
Checking formatting...

All matched files use the correct format.
$ node_modules/.bin/oxlint --tsconfig config/tsconfig/oxlint.core.json extensions/google/oauth.http.ts extensions/google/vertex-adc.ts extensions/google/vertex-adc.oauth-response.test.ts
# passed
$ git diff --check -- extensions/google/oauth.http.ts extensions/google/vertex-adc.ts extensions/google/vertex-adc.oauth-response.test.ts
# passed
$ python .agents/skills/autoreview/scripts/autoreview --mode local --parallel-tests "pnpm test extensions/google/vertex-adc.oauth-response.test.ts extensions/google/oauth.http.test.ts"
autoreview target: local
branch: fix/google-bound-vertex-oauth-responses
engine: codex
autoreview clean: no accepted/actionable findings reported
overall: patch is correct (0.74)
tests exit: 0 after 59s

Notes for reviewers:

  • The 16 MiB cap matches the existing Google OAuth HTTP helper in oauth.http.ts. Legitimate ADC token responses are far smaller; the cap is a fail-closed bound against unbounded wire reads, not a product limit change.
  • This PR intentionally does not include the gzip maxOutputLength hardening present in fix(google-vertex-adc): bound token response body read to prevent OOM #98507. If maintainers prefer one combined fix, that sibling PR is the broader option; this one is the minimal shared-cap alignment for the ADC refresh read site.
  • This PR does not add or migrate persistent state.

AI-assisted: built with Codex. I understand the change: it replaces the unbounded Vertex ADC OAuth token refresh arrayBuffer() read with the shared 16 MiB bounded response reader and adds focused regression tests for normal and oversized streamed refresh bodies.

@clawsweeper

clawsweeper Bot commented Jul 1, 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 clean narrow raw-body cap, but #98507 is the better canonical Vertex ADC OAuth hardening path because it covers the same parser, the same unbounded token-response read, and the decoded gzip-output bound with positive proof and clean mergeability.

Root-cause cluster
Relationship: superseded
Canonical: #98507
Summary: The Google Vertex ADC OAuth token response-size hardening cluster has a broader open canonical PR that covers this PR's raw response cap and the remaining decoded gzip-output bound.

Members:

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

Canonical path: Close this narrower branch and use #98507 as the canonical Google Vertex ADC OAuth response hardening path.

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

Review details

Best possible solution:

Close this narrower branch and use #98507 as the canonical Google Vertex ADC OAuth response hardening path.

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

Yes at source level: current main reaches readGoogleOauthTokenResponsePayload from resolveGoogleVertexAuthorizedUserHeaders and buffers the token response with response.arrayBuffer(). I did not run an OOM reproduction, but the oversized-stream failure path is clear from source and the PR's test shape.

Is this the best way to solve the issue?

No for this branch as the best landing path: the raw-body cap is a correct narrow mitigation, but #98507 is the better canonical fix because it also bounds decoded gzip output in the same parser.

Security review:

Security review cleared: The diff narrows an existing memory-exhaustion path and does not add dependencies, workflows, scripts, permissions, lockfile changes, or external code execution.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • liaoandi: Commit 97d68b6 added compressed Google Vertex ADC token refresh response handling and tests in the same parser area now being hardened. (role: prior related feature contributor; confidence: high; commits: 97d68b69027f; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • steipete: Commit 0b59964 introduced Vertex authorized_user ADC support, and commit 697bafa adjusted token lifetime handling in the same file. (role: feature introducer and recent area contributor; confidence: high; commits: 0b59964ec945, 697bafa9c97d; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • damianFelixPago: Commit f09b4eb expanded production ADC mode support and tests around the same Google Vertex auth boundary. (role: recent Vertex ADC contributor; confidence: medium; commits: f09b4ebe314e; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • wangmiao0668000666: Commit a6aaba7 added the existing Google OAuth response body cap that this PR reuses for the Vertex ADC parser. (role: adjacent shared OAuth cap contributor; confidence: medium; commits: a6aaba76ac66; files: extensions/google/oauth.http.ts, extensions/google/oauth.http.test.ts)

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

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Jul 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 1, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

I'm fine with either path:

  1. Land this narrow wire-body cap if maintainers want the unbounded arrayBuffer() OOM path closed quickly with the shared 16 MiB OAuth cap.
  2. Close this PR in favor of fix(google-vertex-adc): bound token response body read to prevent OOM #98507 if maintainers prefer one combined Vertex ADC OAuth hardening change that also covers gzip decoded-output bounds.

No further code changes planned from my side unless maintainers request them.

@ly85206559
ly85206559 force-pushed the fix/google-bound-vertex-oauth-responses branch from bfb9d4f to 83a679b Compare July 2, 2026 09:11
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 3, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 4, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Jul 5, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jul 5, 2026
@ly85206559 ly85206559 closed this Jul 6, 2026
@ly85206559
ly85206559 force-pushed the fix/google-bound-vertex-oauth-responses branch from 83a679b to a34b8a8 Compare July 6, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google 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: XS 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.

1 participant