Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ public HTTPRestResponse subscribeToTask(ServerCallContext context, String tenant
*/
public HTTPRestResponse getTask(ServerCallContext context, String tenant, String taskId, @Nullable Integer historyLength) {
try {
TaskQueryParams params = new TaskQueryParams(taskId, historyLength, tenant);
TaskQueryParams params;
try {
params = new TaskQueryParams(taskId, historyLength, tenant);
} catch (IllegalArgumentException e) {
throw new InvalidParamsError(e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The error handling logic introduced here uses InvalidParamsError, which is eventually serialized into a JSON response via the HTTPRestErrorResponse.toJson() method (line 950). This method is vulnerable to JSON injection because it manually constructs a JSON string by concatenating the error message without proper escaping. If an error message contains double quotes, newlines, or other special characters, it will result in malformed JSON or allow an attacker to inject additional fields into the response. It is recommended to use a proper JSON serialization library (like the one already used in createSuccessResponse) to generate the error response.

}
Comment on lines +419 to +423
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this correctly handles the exception, using a nested try-catch block adds some visual complexity. For improved readability, consider refactoring this to use a single try block with an additional catch (IllegalArgumentException e) clause. This would flatten the structure and make the error handling logic more straightforward.

Task task = requestHandler.onGetTask(params, context);
if (task != null) {
return createSuccessResponse(200, io.a2a.grpc.Task.newBuilder(ProtoUtils.ToProto.task(task)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public void testGetTaskNotFound() {
Assertions.assertTrue(response.getBody().contains("TaskNotFoundError"));
}

@Test
public void testGetTaskNegativeHistoryLengthReturns422() {
RestHandler handler = new RestHandler(CARD, requestHandler, internalExecutor);

RestHandler.HTTPRestResponse response = handler.getTask(callContext, "", MINIMAL_TASK.id(), -1);

Assertions.assertEquals(422, response.getStatusCode());
Assertions.assertEquals("application/problem+json", response.getContentType());
Assertions.assertTrue(response.getBody().contains("InvalidParamsError"));
}

@Test
public void testListTasksStatusWireString() {
RestHandler handler = new RestHandler(CARD, requestHandler, internalExecutor);
Expand Down
Loading