Skip to content

fix(jsonrpc): reject request ids that are not a string or safe integer (#318) - #323

Open
mcollina wants to merge 1 commit into
mainfrom
fix/318-validate-request-id-type
Open

mcollina wants to merge 1 commit into
mainfrom
fix/318-validate-request-id-type

Conversation

@mcollina

Copy link
Copy Markdown
Member

Summary

checkRequestId only refused numeric ids outside the safe integer range. Any other non-conforming id (null, true, {"a":1}, [1]) was processed and echoed back, e.g. {"id":null,"result":{}}.

The check now refuses every message that carries an id key whose value is not a string or a safe integer. These get -32600 Invalid Request with id: null. The same function runs on the HTTP POST route and on the stdio transport before inject, so both behave the same way.

Behavior that stays the same:

  • A message with no id key is still a notification (HTTP 202, no reply on stdio).
  • A client error response with id: null is still accepted, since JSON-RPC 2.0 section 5 allows it when the request id couldn't be determined.
  • String ids, including empty or very large numeric strings, and safe integer ids still work as before.

On the stdio object:[object Object] in-flight key mentioned in the issue: object ids are now rejected before they reach request handling, so they can no longer end up sharing a slot.

Tests

  • test/index.test.ts: null, true, false, object, array and 1.5 ids get 400 / -32600 / id null. A notification without an id still gets 202. A client error response with a null id is accepted. String and integer ids are echoed.
  • test/stdio.test.ts: the same invalid ids get -32600 / id null. A notification gets no reply. String and integer ids are echoed.

npm run lint, npm run typecheck and npm run test all pass, except distributed-lock.test.ts > should extend Redis lock TTL. That test is timing-based and fails intermittently on its own (1 of 3 isolated reruns), and this change doesn't touch it.

Fixes #318

🤖 Generated with Claude Code

https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9

#318)

checkRequestId only refused unsafe numeric ids, so requests with an id of
null, a boolean, an object or an array were processed and the id echoed
back. Any message that carries an `id` key whose value is not a string or
a safe integer is now answered with -32600 Invalid Request and id: null,
on HTTP and stdio alike. Messages without an `id` key are still handled
as notifications, and a client error response with a null id (JSON-RPC
2.0 section 5) is still accepted.

Fixes #318

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request ids that are not a string or integer are processed and echoed back

1 participant