Repository navigation
fix(mcp): reject request ids over 16 KiB without ending the session - #8681
Conversation
…on (#7768) An id near the response cap could not be echoed, so the writer's fatal output-limit ended the transport. Reject at receive with a bounded -32600 frame carrying a null id and keep serving. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0177XcqQYAvaNnSX736dXsye
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 6 minutes. View limit details
Comment |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
… working The 1 KiB cap broke the #7463 near-cap inventory contract, which deliberately uses a 12 KB escaped id. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0177XcqQYAvaNnSX736dXsye
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Confirmed findings
- PR body prose says 'exceeds 1024 bytes' but the committed constant is 16384 (16 KiB). All code, changelog, spec, and interop doc are internally consistent at 16384; only the author description in the PR body is wrong. Worth flagging for the author to correct the body to avoid reviewer confusion, but not a code defect.
- Changelog says 1024-byte id limit but code and spec mark 16384 bytes; client/operator-facing docs diverge from the actual constant.
- ub-worker-handoff scope (JS-backed worker handoff, async/GC/detach/transfer boundaries, SharedArrayBuffer, postMessage, transferable streams, OffscreenCanvas) is not touched by this Rust-only MCP stdio receive patch; no new JS runtime, spawned Web Worker, or transferable boundary is introduced. The lane therefore has no public issue to surface on this diff.
Verification questions
- Confirm plan/lane posture mismatch: ripr sensor status is 'failed', so the bounded-id and the giant-id stimuli in transport_tests.rs are only locally validated; an independent miri/cargo-test witness is scheduled-late and not yet landed before this gate. Not an oracle defect; flag for human to recheck when cargo-test receipt arrives.
- Confirm sibling call sites that produce a JSON-RPC reply frame: BoundedTransport writer path uses protocol_error_frame(-32600, ...) which already exists and is used by the existing pending_protocol_error path; no new writer code path introduced.
Refuted
- serde_json::to_vec(&request.id) allocation failure on a large id would yield an empty Vec and incorrectly route an oversized id through the admission path.; refuted because: unwrap_or(true) treats Err as oversized and feeds the existing pending_protocol_error writer; the failing allocation is never dereferenced, so this is a false premise on memory-safety grounds.
- The oversized-id branch could share backing storage with the read frame's BytesMut and observe a stale length after a subsequent resize.; refuted because: serde_json::to_vec(&request.id) allocates a fresh Vec; the original BytesMut is not resized, re-sliced, or transferred, and request.id is moved by reference into a local call that does not retain a view into the read buffer.
- Box::from(slice) allocation-failure analysis on the new id-guard path; refuted because: objection not raised by PR diff, seeded thread, or any candidate; per calibration this is a false-premise refutation, not a finding.
- A sibling id-echo path outside transport.rs::receive could still emit an oversized id (notifications or server→client responses).; refuted because: transport.rs::receive is the only decoding site for ClientJsonRpcMessage::Request and writers always construct Response/Error ids themselves, so no second inbound echo exists.
- The diff introduces or alters a JS-backed worker handoff / async transfer / GC boundary that could leak objects, listeners, or detached buffers across worker realms.; refuted because: Constrained file inventory is 8 .rs/.md/.toml files; the Rust source delta is a single receive-path branch wrapping protocol_error_frame and stashing a bounded JSON error in pending_protocol_error. There is no JS engine integration, no Worker ctor, no transferable handle, no SharedArrayBuffer, and no postMessage/Detach path in scope.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Parked follow-ups
- Removed long_request_ids_refuse_typed_before_the_wire_cap and window_sized_envelope_refuses_typed_instead_of_dropping_structured_content stdio tests shipped ids near the 128 KiB response cap; PR confirms their stimulus is now rejected at receive, but those tests were the only stdio coverage for the id-aware envelope budget and typed refusals.
|
Hosted Generated by Claude Code |
…ction recoverable_request_id echoed any string id, so an over-limit id on a request with malformed params bypassed the admission bound. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0177XcqQYAvaNnSX736dXsye
|
Addressed Devin's findings on head f37db51:
Generated by Claude Code |
There was a problem hiding this comment.
Confirmed findings
- PR body summary still describes the new cap as 'exceeds 1024 bytes' while code, spec, interop, and changelog all use 16384 bytes; harmless but should be corrected to match the committed constant.
- PR body prose still claims 'exceeds 1024 bytes' for the id cap, while changelog, transport.rs constant, interop.md, and spec all consistently use 16384. Document drift between PR description and shipped artifact; not a code defect, but reviewers will be confused. Author should update the summary text to match the committed constant.
- The PR body/changelog discrepancy reported earlier should remain corrected to 16384 bytes everywhere; the current committed changelog and specification are consistent.
- Reader-side recheck: with MAX_REQUEST_ID_BYTES=16384 and recoverable_request_id serializing any RequestId variant (string, integer, or null echo path), a malicious client could still spike CPU via serde_json::to_vec on every frame. Bound is small but checked on the hot receive path; consider whether a length-bounded pre-scan on the raw frame would be cheaper than serializing the parsed id.
Verification questions
- Confirm two stdio windows now test only the new id-bound refusal; the id-aware envelope budget on the public wire is no longer exercised by a tests/mcp_stdio.rs case, relying on server_tests.rs/protocol.rs and the 12 KB near-cap inventory test for coverage.
- Confirm pR body summary text says 'exceeds 1024 bytes' for the cap but the committed constant, changelog, spec, and interop doc all use 16384 bytes. Only the human PR body is stale.
- Confirm removing real-stdio near-response-cap envelope tests narrows integration evidence, although retained lower-level tests still pin the id-aware budget.
- Confirm pR body prose diverges from code/spec/docs by stating 'exceeds 1024 bytes' while every committed artifact and the changelog cite 16384 bytes; only the author summary is stale and should be corrected to avoid reviewer confusion.
Evidence gaps
- Cargo-test receipt is scheduled-late, not yet landed; locally validated only. Not an oracle defect, but the bounded-id/giant-id stimuli in transport_tests.rs lack an independent witness before gate.
- ripr sensor status is failed (exit 2); the new bounded-id stimuli on this diff are only locally validated so far. cargo-test is scheduled-late and its receipt is not yet present before this gate. Flagged for a human to recheck when the scheduled receipt lands; not a code defect on this lane.
- Final independent executable confirmation is incomplete in the supplied packet: cargo-test is receipt-absent and ripr failed with exit code 2.
- Model proof intent was rejected by deterministic validation.
Requested by Steven · project thread
Summary
Before: a valid request carrying a string id of 131,072+ characters (under the 256 KiB inbound limit) made the server exit with code 2 and no reply, because the echoed response exceeded the 128 KiB response cap and the writer's output-limit failure is fatal to the transport. Later requests were never answered.
After: ids whose JSON-serialized form exceeds 16 KiB (16384 bytes) are rejected at receive with a bounded
-32600frame carrying"id": null(the id is never echoed), and the session keeps serving. The cap is deliberately well above the existing near-cap inventory contract (#7463), which uses a ~12 KB escaped id and still works.How: new
MAX_REQUEST_ID_BYTESinmcp/mod.rs, checked inBoundedTransport::receivebefore admission, using the existingpending_protocol_errorpath. Spec, interop doc, traceability and a changelog entry updated.Tests: new transport unit test and stdio test (128 KiB id and a just-over-cap id rejected; boundary id and a following ping answered). Three older stdio tests were removed because their stimulus (ids near the response cap) is now rejected at receive; the id-aware envelope budget stays covered by the unit tests in
server_tests.rsandprotocol.rsand by the near-cap inventory test with a 12 KB id. An earlier head used a 1 KiB cap and broke that inventory test in hosted CI; this head raises the cap and passes it locally.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Spec: RIPR-SPEC-0211
ADR: 0022
Governing issue or accepted claim: #5254 (MCP transport and bound edges; this covers the oversized-id fatal-limit case only, found by client-driven probing)
Acceptance delta (one sentence): A request id too large to echo is rejected with a bounded -32600 and the MCP session stays alive.
Candidate Relationships
No stack, replacement or competing candidate known.
Verification
cargo xtask precommitexit 0 on this head;agentic_bench_mcpnear-cap inventory,mcp_stdiooversized-id andmcp::transportunit tests pass locally. Independent review found nothing blocking on the earlier head.Generated by Claude Code
🤖 Generated with Claude Code