Skip to content

fix: stop leaking exception messages to clients via JSON-RPC error data - #486

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
jj-ivx:sanitize-tool-error-messages
Aug 7, 2026
Merged

fix: stop leaking exception messages to clients via JSON-RPC error data#486
koic merged 1 commit into
modelcontextprotocol:mainfrom
jj-ivx:sanitize-tool-error-messages

Conversation

@jj-ivx

@jj-ivx jj-ivx commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Unexpected exceptions raised by tool handlers — and anything reaching JsonRpcHandler's blind rescue StandardError — had their #message echoed verbatim into the JSON-RPC error data member, exposing internals such as class, method and host names to untrusted clients (CWE-209).

  • Server#call_tool no longer appends e.message to the wrapped RequestHandlerError; clients see "Internal error calling tool <name>". Observability is unaffected: the original exception still reaches configuration.exception_reporter via original_error.
  • JsonRpcHandler.process_request's generic rescue StandardError no longer sets data (JSON-RPC 2.0 makes it optional).
  • Capability errors keep their client-facing message ("Server does not support ...") by re-raising through RequestHandlerError — the one channel whose message is deliberately surfaced to clients.

Fixes #485

🤖 Generated with Claude Code

@jj-ivx
jj-ivx marked this pull request as ready for review August 6, 2026 15:56
Tool handler exceptions and anything reaching JsonRpcHandler's blind
rescue had their #message echoed into the error data member, exposing
internals to untrusted clients (CWE-209). Capability errors keep their
client-facing message by re-raising through RequestHandlerError, the
one channel whose message is deliberately surfaced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jj-ivx
jj-ivx force-pushed the sanitize-tool-error-messages branch from c6b475d to f379e13 Compare August 6, 2026 16:28
@koic

koic commented Aug 7, 2026

Copy link
Copy Markdown
Member

For context, this behavior was originally introduced in #194 to improve the developer experience. That said, I think this change is appropriate now. Exposing the message could be made opt-in through configuration for development purposes, but that can be addressed separately if the need arises.

@koic
koic merged commit 2d8210f into modelcontextprotocol:main Aug 7, 2026
11 checks passed
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.

Unexpected tool exceptions leak internal details to clients via JSON-RPC error data

2 participants