fix: fetch adaptor is not enforcing max body or content length#10795
Merged
jasonsaayman merged 1 commit intov1.xfrom Apr 22, 2026
Merged
fix: fetch adaptor is not enforcing max body or content length#10795jasonsaayman merged 1 commit intov1.xfrom
jasonsaayman merged 1 commit intov1.xfrom
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 3 files
Confidence score: 3/5
- There is concrete regression risk in
lib/adapters/fetch.js: the maxContentLength stream-wrapping path should checkresponse.bodyfirst, otherwise no-body responses can throw a TypeError at runtime. - In
lib/helpers/estimateDataURLDecodedBytes.js, the new comment overstates behavior: thebody.lengthfallback is not strictly an upper-bound/over-count-only estimate, which can mislead future maintenance and assumptions. - Given both findings are medium severity (6/10) with high confidence (9/10), this PR has some user-impacting risk and should get a focused fix pass before merging.
- Pay close attention to
lib/adapters/fetch.jsandlib/helpers/estimateDataURLDecodedBytes.js- runtime no-body handling and inaccurate safety-property documentation need correction.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/helpers/estimateDataURLDecodedBytes.js">
<violation number="1" location="lib/helpers/estimateDataURLDecodedBytes.js:77">
P2: Custom agent: **Flag AI Slop and Fabricated Changes**
Added comment claims a safety property (“upper-bound” / “over-counting only”) that the `body.length` fallback does not provide.</violation>
</file>
<file name="lib/adapters/fetch.js">
<violation number="1" location="lib/adapters/fetch.js:315">
P2: Guard the maxContentLength stream-wrapping path with `response.body` to avoid TypeError on no-body responses.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| } | ||
|
|
||
| // Browser/worker fallback: use TextEncoder when available, else fall back to | ||
| // raw string length as an upper-bound heuristic. Both are safe for a DoS |
Contributor
There was a problem hiding this comment.
P2: Custom agent: Flag AI Slop and Fabricated Changes
Added comment claims a safety property (“upper-bound” / “over-counting only”) that the body.length fallback does not provide.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/helpers/estimateDataURLDecodedBytes.js, line 77:
<comment>Added comment claims a safety property (“upper-bound” / “over-counting only”) that the `body.length` fallback does not provide.</comment>
<file context>
@@ -69,5 +69,16 @@ export default function estimateDataURLDecodedBytes(url) {
+ }
+
+ // Browser/worker fallback: use TextEncoder when available, else fall back to
+ // raw string length as an upper-bound heuristic. Both are safe for a DoS
+ // guard (over-counting only makes the check stricter for non-ASCII content).
+ if (typeof TextEncoder === 'function') {
</file context>
| if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) { | ||
| if ( | ||
| supportsResponseStream && | ||
| (onDownloadProgress || hasMaxContentLength || (isStreamResponse && unsubscribe)) |
Contributor
There was a problem hiding this comment.
P2: Guard the maxContentLength stream-wrapping path with response.body to avoid TypeError on no-body responses.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/adapters/fetch.js, line 315:
<comment>Guard the maxContentLength stream-wrapping path with `response.body` to avoid TypeError on no-body responses.</comment>
<file context>
@@ -252,10 +293,27 @@ const factory = (env) => {
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
+ if (
+ supportsResponseStream &&
+ (onDownloadProgress || hasMaxContentLength || (isStreamResponse && unsubscribe))
+ ) {
const options = {};
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by cubic
Enforces
maxBodyLengthandmaxContentLengthin thefetchadapter with pre-checks, streaming checks, and data: URL guards to match the Node HTTP adapter and prevent oversized payloads.Description
maxBodyLengthbefore dispatch for non-GET/HEAD requests; emitERR_BAD_REQUEST.Content-Lengthand reject early if it exceedsmaxContentLength; emitERR_BAD_RESPONSE.data:URLs by estimating decoded size before materializing.ReadableStream.estimateDataURLDecodedByteswith browser-safe fallbacks (TextEncoder/string length).fetchadapter was not enforcing size limits; this aligns behavior with the HTTP adapter and docs.ERR_BAD_REQUEST(request body),ERR_BAD_RESPONSE(response/content).Docs
/docs/to note thefetchadapter now respectsmaxBodyLengthandmaxContentLength, including:Content-Length, streaming enforcement, anddata:URL behavior.Testing
tests/unit/adapters/fetch.test.js:maxBodyLength.Content-LengthexceedsmaxContentLength.data:URLs (base64 and plain).Semantic version impact
fetchadapter with documented/expected limits. Potentially stricter behavior if limits were previously set but unenforced.Written for commit 600048c. Summary will update on new commits.