fix: sanitize internal error messages in transport handlers - #1046
Open
ez-lbz wants to merge 1 commit into
Open
fix: sanitize internal error messages in transport handlers #1046ez-lbz wants to merge 1 commit into
ez-lbz wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
1. Sanitize internal error messages in the JSON-RPC handler
Problem:
JSONRPCHandlerconverted every unexpected (non-A2AError) exception intonew InternalError(t.getMessage()), forwarding the raw exception message — often containing file paths, library names, or class names — to the client in the JSON-RPC error payload (CWE-209, information disclosure / server fingerprinting).Fix (transport/jsonrpc/src/main/java/org/a2aproject/sdk/transport/jsonrpc/handler/JSONRPCHandler.java):
LOGGER(java.util.logging) and a privateinternalError(Throwable)helper that logs the full exception server-side (Level.SEVERE) and returnsnew InternalError("Internal error")with a generic, client-safe message.new InternalError(...getMessage())sites (onMessageSend, onMessageSendStream, onSubscribeToTask, cancel/get/list tasks, push-notification config endpoints, extended agent card, and the streaming subscriberonErrorpath).Fix (transport/jsonrpc/src/test/java/org/a2aproject/sdk/transport/jsonrpc/handler/JSONRPCHandlerTest.java):
testOnMessageSendSanitizesUnexpectedException— a mockedRuntimeExceptionwith a sensitive message yields anInternalErrorwhose message is"Internal error"and does not contain the sensitive text.2. Sanitize internal error messages in the REST handler
Fix (transport/rest/src/main/java/org/a2aproject/sdk/transport/rest/handler/RestHandler.java):
internalError(Throwable)helper (logs atSEVERE, returnsnew InternalError("Internal error")) and replaced all 13new InternalError(...getMessage())sites across send/cancel/get/list/subscribe/push-config/agent-card endpoints, including the streaming error paths.Fix (transport/rest/src/test/java/org/a2aproject/sdk/transport/rest/handler/RestHandlerTest.java):
testSendMessageSanitizesInternalError— asserts a 500 response whose message is"Internal error"(no sensitive text leaked).3. Sanitize internal error messages in the gRPC handler
Problem:
GrpcHandler.handleInternalErrorsentt.getMessage()in the gRPC error description, leaking internal exception details to the client.Fix (transport/grpc/src/main/java/org/a2aproject/sdk/transport/grpc/handler/GrpcHandler.java):
handleInternalErrornow logs the full exception atSEVEREand callshandleErrorwithnew InternalError("Internal error"), so the gRPC status description carries only the generic message.Fix (transport/grpc/src/test/java/org/a2aproject/sdk/transport/grpc/handler/GrpcHandlerTest.java):
testOnMessageInternalErrorIsSanitized— a mockedRuntimeExceptionyields gRPCINTERNALwith description"Internal error"(no sensitive text).Note: exceptions that are already
A2AError(includingInternalErrorthrown by the request handler) still flow through unchanged — sanitization applies to unexpected non-A2A exceptions. Thecompat-0.3module has its own copies of the handlers and was intentionally left unchanged (out of scope).Testing
mvn -pl transport/jsonrpc,transport/grpc,transport/rest test— 127 tests run, 0 failures, 1 skipped (BUILD SUCCESS): JSON-RPC 49, gRPC 41, REST 37, including the 3 new sanitization regression tests.mvn -pl reference/jsonrpc test— 198 tests run, 0 failures, 0 skipped (BUILD SUCCESS).