Skip to content

Cap the fetch tracker's recorded response body (GHSA-9w48-x22j-rrm7) - #2944

Merged
cliffhall merged 4 commits into
v2/mainfrom
v2/fix/ghsa-9w48-cap-tracked-response-body
Nov 11, 2026
Merged

cliffhall merged 4 commits into
v2/mainfrom
v2/fix/ghsa-9w48-cap-tracked-response-body

Conversation

@cliffhall

@cliffhall cliffhall commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Closes #2948

The fix was developed and reviewed in the advisory's private fork. These are the reviewed commits, pushed here unchanged. Tracking issue: #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 uncapped response.clone().text(). isLongLivedStreamResponse treats only GET event streams as unbounded, so a POST answered with text/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

  • The 401/403 challenge reader is generalized into 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).
  • Past the cap, the recorded body is the prefix plus TRUNCATED_BODY_SUFFIX, or WITHHELD_TRUNCATED_JSON_BODY when it looks like JSON, since a cut JSON prefix cannot be redacted. This reuses the challenge path's recordableBody rule.
  • Only the clone is cancelled. 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.
  • A small behavior refinement in the shared reader: a body is marked truncated only once a byte beyond the cap actually arrives. A body that ends exactly at a cap is now recorded whole.

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/fetch limit (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. GET long-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's BodyPreview shows its existing "Body too large to preview" note. An over-cap JSON body is different: it is recorded as the short WITHHELD_TRUNCATED_JSON_BODY placeholder, and the web Network tab and the TUI display that placeholder text. This includes a legitimate application/json tool result over 1 MiB, which used to be recorded in full. parseJsonRpcError returns null for 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":
    • An endless POST SSE body is recorded as exactly TRACKED_BODY_MAX_BYTES plus the suffix.
    • After the cap the source stops being pulled, so nothing keeps buffering.
    • The caller's stream still reads 2× past the cap.
    • Also covered: a body exactly at the cap is recorded intact, an over-cap JSON body is withheld, an empty chunk is skipped, a mid-read stream error records nothing, and a throwing updateResponseBody listener is contained.
    • Before the fix this file crashes its worker with a heap OOM.
  • clients/web/src/test/integration/mcp/fetchTracking-capped-body.test.ts uses a real node:http server with Node fetch, i.e. the real undici tee:
    • An endless POST SSE stream: the caller reads 4× the cap while the recorded body is capped and marked truncated.
    • A finite 3 MiB SSE stream reaches the caller whole and in order (no stall behind the cancelled clone), and its recorded copy is truncated.
    • A normal POST SSE body is recorded intact.
    • Two of these three fail before the fix.

Gate

npm run format, then npm run local:gate: green (exit 0). core/mcp/fetchTracking.ts coverage: 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

cliffhall and others added 2 commits November 11, 2026 12:27
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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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]>
@cliffhall
cliffhall requested a balanced review from Copilot November 11, 2026 18:48
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1 (1 inline finding, nothing suppressed)

  • Unbounded poll for the recorded body in the integration test. Fixed in 06f0edc: it is now a vi.waitFor with a 10s deadline, inside the 30s test budget. A missing body update fails at the wait and stops polling.

npm run local:gate passed on 06f0edc. I have requested round 2.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues blocking the response-body recording cap changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
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.

@cliffhall
cliffhall merged commit bc08507 into v2/main Nov 11, 2026
11 checks passed
@cliffhall
cliffhall deleted the v2/fix/ghsa-9w48-cap-tracked-response-body branch November 11, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GHSA-9w48-x22j-rrm7] - [v2] - Network tracker buffers a POST event-stream response with no size limit

2 participants