Repository navigation
Cap the fetch tracker's recorded response body (GHSA-9w48-x22j-rrm7) - #2944
Merged
Merged
Conversation
The fetch tracker recorded every non-long-lived response body with an uncapped `response.clone().text()`. A POST answered with text/event-stream is classified as bounded, so a stream that never ends grew the clone's buffer without limit in the host process. Read the clone through a capped reader instead, shared with the 401/403 challenge path: keep at most TRACKED_BODY_MAX_BYTES (1 MiB), record the prefix marked truncated (or withheld when it looks like JSON, since a cut JSON prefix cannot be redacted), and cancel only the clone, so the stream the transport consumes keeps flowing. A body ending exactly at a cap is now recorded whole rather than marked truncated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The regression test uses an unbounded poll that keeps scheduling timers when the body update never arrives, leaking into subsequent tests and obscuring the failure behind a generic timeout.
1 open issue
What changed in this PR
This PR addresses GHSA-9w48-x22j-rrm7 by bounding response-body recording in the shared MCP fetch tracker without interrupting the caller’s stream.
Changes:
- Caps ordinary recorded responses at 1 MiB while preserving challenge-body limits.
- Marks truncated bodies and withholds incomplete JSON to preserve secret redaction.
- Adds unit and real-socket tests for bounded recording and continued caller delivery.
| File | Description |
|---|---|
core/mcp/fetchTracking.ts |
Generalizes the capped reader and applies it to ordinary response recording. |
clients/web/src/test/integration/mcp/fetchTracking-capped-body.test.ts |
Tests truncation and uninterrupted caller delivery over real HTTP streams. |
clients/web/src/test/core/mcp/fetchTracking.test.ts |
Covers cap boundaries, JSON withholding, buffering, and error handling. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
Member
Author
|
Copilot round 1 (1 inline finding, nothing suppressed)
|
Member
Author
|
Copilot review loop closed. Round 2 on 06f0edc came back clean: no inline comments, no suppressed comments, and the round-1 finding is marked resolved. Per pr-flow 7c, a clean round ends the loop. |
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.

Closes #2948
Advisory: GHSA-9w48-x22j-rrm7 (v2 only).
Problem
createFetchTracker(core/mcp/fetchTracking.ts) recorded every response body that is not a long-lived stream with an uncappedresponse.clone().text().isLongLivedStreamResponsetreats onlyGETevent streams as unbounded, so aPOSTanswered withtext/event-stream(normal for streamable HTTP) was buffered with no limit. A stream that never ends grew the clone's buffer until the host process ran out of memory. The web backend enables tracking on every connect.Fix
readCappedBody(response, maxBytes, timeoutMs?), and the ordinary body path now uses it with a new named cap,TRACKED_BODY_MAX_BYTES= 1 MiB. The challenge path is unchanged (64 KiB, 2 s).TRUNCATED_BODY_SUFFIX, orWITHHELD_TRUNCATED_JSON_BODYwhen it looks like JSON, since a cut JSON prefix cannot be redacted. This reuses the challenge path'srecordableBodyrule.Response.clone()tees the body, and cancelling one tee branch leaves the other branch flowing. After that cancel the tee stops queueing chunks for the clone, so nothing keeps buffering on the tracker's side. The cancel is not awaited, because on a tee branch it settles only when both branches are cancelled.Why 1 MiB: the Network tab previews at most 100,000 characters inline (
MAX_INLINE_BODY_CHARS), which is at most ~300 KB of UTF-8. So every body a user can actually read there is still recorded whole. One entry can never exceed the cap, and that matters because the log holds up to 1000 entries and re-publishes each one to the browser and to session storage. The cap is also well under the 4 MiB/api/fetchlimit (MAX_PROXIED_RESPONSE_BYTES).Why not route POST SSE through
watchLongLivedStream: a POST SSE reply is bounded by protocol, and recording its raw payload is what the Network tab shows for every ordinary request that streams its reply (tool calls with progress, etc.). Watching would replace that payload with an event count on every normal request, in order to handle a misbehaving server. Capping keeps the display for well-behaved servers and bounds the misbehaving one.GETlong-lived streams are unaffected.Network UI: a truncated non-JSON body (an SSE payload, plain text) is recorded as the 1 MiB prefix plus the suffix. That is over the 100,000-character preview limit, so
NetworkEntry'sBodyPreviewshows its existing "Body too large to preview" note. An over-cap JSON body is different: it is recorded as the shortWITHHELD_TRUNCATED_JSON_BODYplaceholder, and the web Network tab and the TUI display that placeholder text. This includes a legitimateapplication/jsontool result over 1 MiB, which used to be recorded in full.parseJsonRpcErrorreturnsnullfor both shapes, the filter is a substring match, and the TUI renders the string as text, so no consumer needed changes.Tests
clients/web/src/test/core/mcp/fetchTracking.test.ts, new describe block "recorded body cap":TRACKED_BODY_MAX_BYTESplus the suffix.updateResponseBodylistener is contained.clients/web/src/test/integration/mcp/fetchTracking-capped-body.test.tsuses a realnode:httpserver with Nodefetch, i.e. the real undici tee:Gate
npm run format, thennpm run local:gate: green (exit 0).core/mcp/fetchTracking.tscoverage: 99.35 stmts / 100 branch / 100 funcs / 99.28 lines. The two uncovered lines are pre-existing and outside this change.🤖 Generated with Claude Code