Repository navigation
fix(web-shared): bound response.text() fallback to honor maxBytes - #99884
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 6:45 PM ET / 22:45 UTC. Summary PR surface: Source +10, Tests +17. Total +27 across 4 files. Reproducibility: yes. source-reproducible. Current main and v2026.6.11 can fall through to whole-body arrayBuffer() or text() after a maxBytes request when no readable stream is available; I did not run a live repro in this read-only review. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep the shared fail-closed bounded-read contract if maintainers accept the plugin-visible compatibility change, then clear proof/check state before landing. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible. Current main and v2026.6.11 can fall through to whole-body arrayBuffer() or text() after a maxBytes request when no readable stream is available; I did not run a live repro in this read-only review. Is this the best way to solve the issue? Yes, with maintainer acceptance of the compatibility change. Failing closed before whole-body fallbacks is the narrowest maintainable fix for the memory-bound contract, and the PR preserves uncapped fallback behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8d469711294a. Label changesLabel justifications:
Evidence reviewedPR surface: Source +10, Tests +17. Total +27 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (10 earlier review cycles; latest 8 shown)
|
8f53e90 to
5eb780a
Compare
5eb780a to
cd5f3bd
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Maintainer land-ready proofReviewed exact head: The original patch truncated only after Evidence:
Review commands:
Sanitized direct AWS Crabbox was unavailable because the broker returned HTTP 500 code 1101. No contributor code ran on a credential-hydrated Testbox; exact-head scheduled CI is the execution proof backend. Best-fix judgment: the shared helper is the right owner because all capped callers need the same pre-read contract. Post-read slicing, downstream guards, or per-caller fallbacks would retain or duplicate the allocation bug. The caller set, public SDK barrels, adjacent helper, and current No screenshot applies: this is a response-stream memory-boundary change. |
readResponseText's .text() fallback path ignored the maxBytes option, reading the full body unbounded. When a foreign Response lacks a body stream (no getReader) and no arrayBuffer(), the .text() call was the last resort — but maxBytes was never applied. - Honor maxBytes in the .text() fallback: truncate + set truncated=true - Under-cap responses pass through unchanged - No maxBytes set → original behavior preserved (regression safe)
Replace text.length/text.slice (character-level) with TextEncoder/ TextDecoder (byte-level) so the maxBytes cap is respected at byte granularity, consistent with the bounded-stream path at lines 240-298. - bytes.byteLength > maxBytes instead of text.length > maxBytes - TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation - bytesRead reports actual bytes, not character count
When maxBytes is set the caller expects bounded memory. The .text() fallback path buffers the full body before any post-read check, defeating the cap. Fail-closed by returning empty with truncated=true instead of calling .text() unbounded. Without maxBytes .text() is safe — the caller accepts full allocation.
The .text() fallback used text.length (characters) and text.slice (char-level) against a byte-level maxBytes cap. Use TextEncoder/ TextDecoder for byte-accurate comparison and truncation. - bytes.byteLength > maxBytes instead of text.length > maxBytes - TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation - bytesRead reports actual byte count, not character count
570736c to
0db4df3
Compare
|
Merged via squash.
|
…enclaw#99884) * fix(web-shared): bound response.text() fallback to honor maxBytes readResponseText's .text() fallback path ignored the maxBytes option, reading the full body unbounded. When a foreign Response lacks a body stream (no getReader) and no arrayBuffer(), the .text() call was the last resort — but maxBytes was never applied. - Honor maxBytes in the .text() fallback: truncate + set truncated=true - Under-cap responses pass through unchanged - No maxBytes set → original behavior preserved (regression safe) * fix(web-shared): use byte-level truncation in .text() fallback Replace text.length/text.slice (character-level) with TextEncoder/ TextDecoder (byte-level) so the maxBytes cap is respected at byte granularity, consistent with the bounded-stream path at lines 240-298. - bytes.byteLength > maxBytes instead of text.length > maxBytes - TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation - bytesRead reports actual bytes, not character count * fix(web-shared): refuse unbounded .text() when maxBytes is set When maxBytes is set the caller expects bounded memory. The .text() fallback path buffers the full body before any post-read check, defeating the cap. Fail-closed by returning empty with truncated=true instead of calling .text() unbounded. Without maxBytes .text() is safe — the caller accepts full allocation. * fix(web-shared): byte-level truncation in .text() fallback with maxBytes The .text() fallback used text.length (characters) and text.slice (char-level) against a byte-level maxBytes cap. Use TextEncoder/ TextDecoder for byte-accurate comparison and truncation. - bytes.byteLength > maxBytes instead of text.length > maxBytes - TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation - bytesRead reports actual byte count, not character count * fix(web): fail closed on unbounded response fallbacks * test(web): use streaming response fixtures --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
readResponseTextenforcesmaxByteswhile reading a WebReadableStream, but its fallback methods calledarrayBuffer()ortext(). Both methods materialize the entire body before returning, so truncating their result cannot provide the requested memory bound.Why This Change Was Made
When a byte cap is requested and the response has no readable stream, the helper now fails closed without invoking either whole-body fallback. It returns an empty, truncated result; a native bodyless
Responseremains an empty, non-truncated result. Uncapped callers retain the existingarrayBuffer()andtext()compatibility paths, with UTF-8 byte accounting for text-only response-like objects.This keeps the public helper's
maxBytescontract honest: capped calls either read a bounded stream or avoid an unbounded allocation.User Impact
Normal Fetch responses continue through the bounded stream path. Nonstandard or mocked response-like objects without a readable stream no longer risk an unbounded whole-body allocation when a caller asks for a cap; callers receive the existing
truncatedsignal instead.Evidence
arrayBuffer()nortext()is called whenmaxBytesis set without a bounded stream source.web-shared,web-fetch.cf-markdown, andweb-tools.fetch; the fixtures now use native streamingResponseobjects.0db4df3fbc85bc4c0e05506569524985f836c28d: no accepted/actionable findings.