Skip to content

fix(google-vertex-adc): bound token response body read to prevent OOM - #98507

Closed
lzyyzznl wants to merge 1 commit into
openclaw:mainfrom
lzyyzznl:fix/vertex-adc-bound-response-read
Closed

lzyyzznl wants to merge 1 commit into
openclaw:mainfrom
lzyyzznl:fix/vertex-adc-bound-response-read

Conversation

@lzyyzznl

@lzyyzznl lzyyzznl commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The readGoogleOauthTokenResponsePayload function in vertex-adc.ts buffers the full Google OAuth token response before parsing. A malicious or misconfigured OAuth endpoint could send a very large response, causing the gateway process to run out of memory.

This is the same class of issue as #98424 but in the Google Vertex token-refresh path.

Why This Change Was Made

The original code used response.arrayBuffer() which buffers the entire response body in memory before parsing. This PR replaces that with readResponseWithLimit from the plugin SDK, which uses a streaming reader with a 16 MiB byte cap.

Changes in this iteration (v3)

Replaced ISIZE pre-check with bounded gunzip (maxOutputLength):

  • The previous ISIZE (gzip trailer uncompressed size) pre-check was modulo 2^32 and could be bypassed by a 4 GiB+ payload with ISIZE = 0
  • Now uses Node.js zlib's gunzipSync(bytes, { maxOutputLength }) which limits decompression output at the zlib layer before full allocation
  • This is both more correct (zlib-native, not ad-hoc header parsing) and more secure (no modulo wrap-around)

Fixed content-encoding header handling:

  • Removed the content-encoding header fallback from shouldGunzipGoogleOauthTokenResponse
  • Node.js fetch auto-decompresses gzip bodies and may leave content-encoding: gzip on the response, causing gunzipSync to fail on already-decompressed data
  • Now only checks gzip magic bytes (0x1f 0x8b) to decide whether to decompress

Changes in this iteration (v4)

Node 24 compatibility - gzip overflow error code:

  • Node 24.18.0's gunzipSync throws ERR_BUFFER_TOO_LARGE (RangeError) when maxOutputLength is exceeded, not ERR_ZLIB_OUTPUT_LENGTH_EXCEEDED as on Node <24
  • Updated the catch block to handle both error codes, ensuring correct behavior across all supported Node versions

Removed proof script & added focused regression tests:

  • Deleted scripts/proof-real-behavior.mjs (the inlined proof script)
  • Restored extensions/google/vertex-adc.test.ts with 11 focused tests covering all bounded-read and overflow scenarios

User Impact

None under normal operation. ADC token responses are typically < 10 KiB. The 16 MiB cap is far above any legitimate response size.

Evidence

Real behavior proof — production module via HTTP (Node 24.18.0)

Imports readGoogleOauthTokenResponsePayload from the actual built production module (dist/extensions/google/vertex-adc.js) and exercises it against a local HTTP server with real fetch() requests — no inline implementation, no mocking.

╔══════════════════════════════════════════════════════════════╗
║  Real Behavior Proof — PR #98507
║  Production module: dist/extensions/google/vertex-adc.js
║  Node: v24.18.0
╚══════════════════════════════════════════════════════════════╝

  ✅ Normal token response
  ✅ Gzip-compressed token (raw bytes, no content-encoding header)
  ✅ Oversized wire (~20 MB > 16 MiB)
  ✅ Gzip compressed overflow (raw bytes, 32 MiB → 32 KB wire)
  ✅ Empty body
  ✅ Invalid JSON
  ✅ OAuth error response

  Results: 7 passed, 0 failed
  Production module: dist/extensions/google/vertex-adc.js

Unit tests (focus on bounded read behavior)

11 dedicated regression tests in extensions/google/vertex-adc.test.ts:

 ✓ parses a valid token response
 ✓ returns undefined for an empty body
 ✓ returns undefined for invalid JSON
 ✓ handles gzip-compressed token responses
 ✓ parses error responses with error_description
 ✓ throws on response exceeding 16 MiB via stream
 ✓ succeeds on response just under 16 MiB via stream
 ✓ handles non-streaming Response via arrayBuffer fallback
 ✓ throws on non-streaming oversized response via arrayBuffer fallback
 ✓ throws on gzip response that decompresses past decoded cap
 ✓ handles whitespace-only body gracefully

Key findings

  1. Normal token responses — bounded reader accepts without regression
  2. Gzip-compressed token responses — decompressed and parsed correctly (magic-byte detection, no content-encoding dependency)
  3. Oversized wire responses (>16 MiB) — caught with descriptive error; memory bounded
  4. Gzip compressed overflow (small wire, huge decompressed) — caught by the bounded gunzip maxOutputLength option on both Node <24 (ERR_ZLIB_OUTPUT_LENGTH_EXCEEDED) and Node 24+ (ERR_BUFFER_TOO_LARGE)
  5. Empty body and invalid JSON — handled gracefully (returns undefined)
  6. OAuth error responses — error_description parsed correctly
  7. The 16 MiB cap is far above expected ADC token responses (< 10 KiB)

@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already fixes the reported Vertex ADC OOM class with a stricter 1 MiB wire/decompression limit and end-to-end authorized-user refresh tests; the PR’s remaining differences loosen that limit, export a private parser for duplicate lower-level tests, or change error wording without adding necessary behavior.

Root-cause cluster
Relationship: superseded
Canonical: #100483
Summary: The reliability batch is the canonical landed fix for the response-size and decompression OOM class; the merged ADC timeout PR adds adjacent deadline coverage, while the other proposals closed unmerged.

Members:

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

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep current main’s private parser, stricter 1 MiB wire/decompression ceiling, and end-to-end refresh-path tests; do not merge the stale 16 MiB implementation unless a distinct regression is demonstrated later.

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

Yes. The pre-fix unbounded arrayBuffer() and gzip paths are clear from history, and current main has explicit owner-level regression tests for both overflow cases.

Is this the best way to solve the issue?

No, this branch is no longer the best solution. Current main uses a stricter limit and tests the actual authorized-user refresh entry point without expanding the parser’s exported surface.

Security review:

Security review cleared: The diff adds no dependency, workflow, permission, secret, or supply-chain surface; the security-relevant memory protection is already present on current main.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current source bounds wire and decoded bodies: Current main reads the OAuth token response through readResponseWithLimit at 1 MiB and passes the same cap to gunzipSync(maxOutputLength), covering oversized wire responses and compressed expansion. (extensions/google/vertex-adc.ts:296, aaf5ab910cbe)
  • Current tests exercise the real refresh entry point: The Google transport suite calls resolveGoogleVertexAuthorizedUserHeaders and verifies rejection for a body above 1 MiB and gzip output expanding above 1 MiB, covering the invariant at the owner-level caller. (extensions/google/transport-stream.test.ts:1454, aaf5ab910cbe)
  • Fix provenance: Commit aaf5ab910cbe35c9cbd491c0d1755aa25b413be9 landed the wire bound, bounded decompression, and regression tests as fix(google): bound Vertex response decompression, sourced from the overlapping Google hardening work. (extensions/google/vertex-adc.ts:299, aaf5ab910cbe)
  • Adjacent merged follow-through: Merged fix(google): add timeout to Vertex ADC token refresh #102050 kept the bounded body consumption under the refresh deadline and consolidated the current ADC owner path; it is complementary provenance, not a remaining response-size gap. (extensions/google/vertex-adc.ts:251, e5259fa8bb4c)
  • Supported Node behavior checked: Direct probes on installed Node 22.23.1 and Node 24.18.0 both produced ERR_BUFFER_TOO_LARGE when bounded gunzip output exceeded maxOutputLength; Node 24 fetch also auto-decompressed gzip while retaining the header, which current main handles by falling back to the decoded bytes. (extensions/google/vertex-adc.ts:314, d11d1d0ee64d)
  • Current-main-only release provenance: No Git tag contains the fix commit, and the newest published release shown was v2026.7.1-beta.2 from July 5, 2026, before the fix landed; this implementation is on current main but not yet in a published release. (extensions/google/vertex-adc.ts:299, aaf5ab910cbe)

Likely related people:

  • steipete: Authored the merged reliability commit that added the 1 MiB wire/decompression bounds and owner-level regression tests, then contributed most follow-up commits in the ADC timeout work. (role: introduced current bounded implementation; confidence: high; commits: aaf5ab910cbe, f88f3508a3a4, 6ca17c4e03ab; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • Alix-007: Authored the merged Vertex ADC timeout PR that finalized deadline coverage around the same bounded response-consumption path. (role: recent adjacent contributor and merger-path author; confidence: high; commits: e80872cdf98f, 2cc02c4f41d3, e5259fa8bb4c; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • 黄剑雄0668001315: The landed reliability commit credits this contributor for the Google Vertex decompression-bound change sourced from the overlapping hardening proposal. (role: source contributor for decompression hardening; confidence: medium; commits: aaf5ab910cbe; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)

Codex review notes: model internal, reasoning high; reviewed against d11d1d0ee64d; fix evidence: commit aaf5ab910cbe, main fix timestamp 2026-07-05T23:08:51Z.

@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. labels Jul 1, 2026
@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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.

@openclaw-barnacle openclaw-barnacle Bot added 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 Jul 1, 2026
@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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 the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L and removed size: S labels Jul 1, 2026
@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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.

@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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.

@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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.

@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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 commented Jul 1, 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 1, 2026
@lzyyzznl
lzyyzznl force-pushed the fix/vertex-adc-bound-response-read branch from f7473af to dfcb769 Compare July 1, 2026 16:31
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L and removed size: S labels Jul 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 1, 2026
@lzyyzznl

lzyyzznl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 1, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: S and removed scripts Repository scripts size: L labels Jul 1, 2026
@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 1, 2026
Replace unbounded response.arrayBuffer() with readResponseWithLimit
capped at 16 MiB. Add decoded-output cap after gunzipSync and use
bounded gunzip (maxOutputLength) to prevent compressed overflow OOM.

- readResponseWithLimit for wire-level cap (16 MiB)
- MAX_DECODED_TOKEN_BODY_BYTES post-gunzip safety check
- maxOutputLength option for Node 22+ bounded decompression
- 10 boundary tests: valid JSON, empty, invalid, gzip, oversized,
  near-boundary, non-streaming fallback, whitespace-only
- Handle Node 24 ERR_BUFFER_TOO_LARGE from gunzipSync

Ref. #98507
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant