Skip to content

[Bug]: Trusted response buffering checks maxBytes only after consuming the entire stream #137

Closed

Description

@jimhoyd

Runtime revision and environment

c984d72; Node 26.8.2, macOS arm64. Local synthetic review probe.

Minimal reproduction

A trusted function returns a finite ReadableStream of twenty 1024-byte chunks. Configure TrustedFunctions with maxBytes: 1024. Count pulls in the synthetic stream. src/trusted-functions.ts:145-148 calls response.arrayBuffer() before checking length.

Relevant output

The call returns 502 only after all 20,480 bytes have been consumed. A second finite stream (ten chunks, 10ms per chunk) with timeoutMs:25 returns 504 after two chunks, but continues to consume all ten; cancel() is never called.

Expected: count bytes while reading; cancel the reader when the output budget/deadline is exceeded. Clean up on HEAD too. This is about host-owned response consumption, not forcibly interrupting arbitrary trusted application code. Buffering can exhaust memory before the configured output limit has any effect. No OOM or production traffic was exercised.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions