Repository navigation
fix(infra): bound response body read in non-streaming fallback paths - #101313
chenxiaoyu209 wants to merge 9 commits into
Conversation
…treaming fallback The non-streaming fallback in readResponseBodySnippet called response.text() without any size limit, buffering the entire response before the maxBytes check. Switch to readResponsePrefix which caps the read at maxBytes bytes. The streaming path was already bounded — only the !body.getReader fallback was vulnerable. Fixes #101269
…nt-Length guard - Add null-body early return in readResponsePrefix to avoid arrayBuffer() call - Add Content-Length check before arrayBuffer() in non-streaming path - Export readResponsePrefix from http-body.ts (was private) - Replace response.text() with readResponsePrefix in readResponseBodySnippet - Add 2 regression tests for Content-Length gate and null-body short-circuit Ref. #101270
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close this PR as superseded by the proof-positive canonical fix in #101270; current main still has the bug, but keeping two active branches for the same compatibility-sensitive no-reader fallback is not useful. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Review and land #101270 as the canonical fix for #101269, then close the linked issue after merge. So I’m closing this here and keeping the remaining discussion on #101270, #101269, and #101278. Review detailsBest possible solution: Review and land #101270 as the canonical fix for #101269, then close the linked issue after merge. Do we have a high-confidence way to reproduce the issue? Yes from source inspection: current main's no-reader Is this the best way to solve the issue? No for this branch as the landing path. The code direction is plausible, but #101270 is the narrower proof-positive canonical PR for the same root cause. Security review: Security review cleared: The diff only changes infra response-reading code and tests; it adds no dependencies, workflows, scripts, package metadata, permissions, or secret handling. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 7c0a7c8be210. |
…ength is missing or invalid
|
Real behavior proof for the fail-closed no-reader path: What changed since last review:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Updated with full no-reader coverage. All 7 no-reader readResponsePrefix no-reader path behavior (7 new tests)
No path calls @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Fixed the Added a test iterating over @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Complete fail-closed refactor: What changedThe no-reader fallback now has exactly two outcomes:
No path calls Test resultsNo-reader scenarios covered
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
What Problem This Solves
readResponseBodySnippetinsrc/infra/http-error-body.tshas a non-streaming fallback path that callsresponse.text()without any size limit, potentially buffering an entire provider error response into memory before themaxBytescheck runs. Similarly,readResponsePrefixinsrc/infra/http-body.tshas a no-reader fallback that callsresponse.arrayBuffer()without bounds.This can exhaust Gateway memory when a provider returns an oversized error body.
Fixes #101269
Why This Change Was Made
readResponsePrefixand reuse it inreadResponseBodySnippetinstead of the unboundedresponse.text()pathreadResponsePrefix— when no ReadableStream reader is available, checkContent-Lengthheader before callingarrayBuffer()to avoid materializing oversized bodiesbodyis null, return immediately without callingarrayBuffer()User Impact
Gateway error-path memory usage is now bounded at
maxBytesregardless of whether the response body is a ReadableStream or a plain object. No API or behavior change for callers.Evidence
oxfmt,oxlint)Number.parseInt/Number.isNaN)🤖 Generated with Claude Code