fix: stop leaking exception messages to clients via JSON-RPC error data
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>
This commit is contained in:
parent
d51d4a0f91
commit
f379e13b47
1 changed files with 23 additions and 14 deletions
|
|
@ -135,11 +135,12 @@ module JsonRpcHandler
|
|||
success_response(id: id, result: result)
|
||||
rescue MCP::Server::RequestHandlerError => e
|
||||
handle_request_error(e, id, id_validation_pattern)
|
||||
rescue StandardError => e
|
||||
rescue StandardError
|
||||
# The exception message is deliberately not echoed into `data`: it can carry
|
||||
# internals that must not reach untrusted clients (CWE-209).
|
||||
error_response(id: id, id_validation_pattern: id_validation_pattern, error: {
|
||||
code: ErrorCode::INTERNAL_ERROR,
|
||||
message: "Internal error",
|
||||
data: e.message,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue