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 @@ -165,7 +165,26 @@ private ListSessionsResponse parseListSessionsResponse(
@Override
public Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) {
validateSessionId(sessionId);
return listEventsInternal(appName, sessionId, /* filter= */ null);
String reasoningEngineId = parseReasoningEngineId(appName);
return client
.getSession(reasoningEngineId, sessionId)
.flatMapSingle(
getSessionResponseMap -> {
// Enforce ownership using the owner reported by the backend, not the
// requested user id, mirroring the check getSession/deleteSession use.
// Deny as empty so existence is not revealed to a non-owner.
String ownerUserId =
Optional.ofNullable(getSessionResponseMap.get("userId"))
.map(JsonNode::asText)
.orElse(null);
if (!userId.equals(ownerUserId)) {
return Single.just(ListEventsResponse.builder().build());
}
return listEventsInternal(appName, sessionId, /* filter= */ null);
})
// No session found at all (rather than an ownership mismatch): behave the
// same as before, returning an empty response instead of erroring.
.defaultIfEmpty(ListEventsResponse.builder().build());
}

private Single<ListEventsResponse> listEventsInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ public void getSession_wrongUser_returnsEmpty() {
.isNull();
}

@Test
public void listEvents_wrongUser_returnsEmpty() {
// Session "1" belongs to "user" and has an event in eventMap (MOCK_EVENT_STRING).
// A different user must not be able to read those events - mirrors
// getSession_wrongUser_returnsEmpty above, applied to listEvents.
ListEventsResponse response =
vertexAiSessionService.listEvents("123", "attacker", "1").blockingGet();

assertThat(response.events()).isEmpty();
}

@Test
public void deleteSession_wrongUser_deniedAndSessionKept() {
// The ownership error surfaces on subscription, so hoist the Completable out.
Expand Down