fix(core): validate RequestId integers against Number.MAX_SAFE_INTEGER#1806
fix(core): validate RequestId integers against Number.MAX_SAFE_INTEGER#1806lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
OAuth 2.1 §3.2 requires token endpoint requests to use application/x-www-form-urlencoded regardless of grant type. Add an explicit header.set() call immediately before the fetch in executeTokenRequest() to prevent any addClientAuthentication implementation from accidentally overriding the Content-Type. Fixes modelcontextprotocol/inspector#1160
Per JSON-RPC spec and JavaScript Map semantics, integer request IDs must be safe integers. When a request id exceeds Number.MAX_SAFE_INTEGER, JavaScript Map lookups silently lose precision, causing the server to never find the matching response and hang permanently (Issue modelcontextprotocol#1765). The fix adds a zod .refine() to RequestIdSchema that rejects any integer with absolute value > Number.MAX_SAFE_INTEGER. The JSON-RPC error response is returned immediately at parse time, keeping the server responsive. Reproduction: send any JSON-RPC request with id: 9007199254740992 (MAX_SAFE_INTEGER + 1) — previously froze the server permanently. Now: returns JSON-RPC InvalidRequest error immediately. Fixes modelcontextprotocol#1765.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
Closing per #1765. The reporter confirmed this was a fuzzing find, not a real-world scenario. Precision loss for numeric IDs above |
Per JSON-RPC spec and JavaScript Map semantics, integer request IDs must be safe integers. When a request
idexceedsNumber.MAX_SAFE_INTEGER, JavaScript Map lookups silently lose precision, causing the server to never find the matching response and hang permanently.Bug
Send any JSON-RPC request with
id: 9007199254740992(MAX_SAFE_INTEGER + 1):{"jsonrpc":"2.0","id":9007199254740992,"method":"tools/list"}Before: Server becomes permanently unresponsive — no crash, no error, requires manual restart.
After: Returns JSON-RPC
InvalidRequesterror immediately, server stays responsive.Root Cause
RequestIdSchema = z.union([z.string(), z.number().int()])accepts any integer. When such an ID is used as a JavaScript Map key (in_requestResponseMapand_requestToStreamMapping), precision is lost:The server waits indefinitely for a response it can never route.
Fix
Added
.refine()toRequestIdSchemato validate integer IDs againstNumber.MAX_SAFE_INTEGER:The JSON-RPC error response is returned at parse time — the server remains fully functional.
Fixes #1765.