Description
I see this has already been mentioned in #1341 for version 1.2.1 but has not been remedied or had any responses. Following is a description of the bug and a suggested fix. This could be seen as a security vunerability.
Describe the bug
When get_session in DatabaseSessionService is called events from different users with the same session_id all get fetched/loaded. F.x. user 'malicious' tries to get events from session 'main' from the database and also gets events from user 'example' using the same session_id.
To Reproduce
Steps to reproduce the behavior:
Run the ADK using DatabaseSessionService with a single session_id. With two or more users create sessions and in turn events and log the returned events.
Expected behavior
Expectation is for the get_session to only have the events for the corresponding user.
Desktop:
- OS: macOS 15.5
- Python version(python -V): Python 3.13.5
- ADK version(pip show google-adk): 1.4.2
- Database: PostgreSQL 14.18
Additional context
I believe the only fix needed to get indentical behaviours between InMemorySessionService and DatabaseSessionService is the following code in src/google/adk/sessions/database_session_service.py:444
storage_events = (
session_factory.query(StorageEvent)
.filter(StorageEvent.session_id == storage_session.id)
.filter(StorageEvent.user_id == user_id)
.filter(timestamp_filter)
.order_by(StorageEvent.timestamp.desc())
.limit(
config.num_recent_events
if config and config.num_recent_events
else None
)
.all()
)
As opposed to
storage_events = (
session_factory.query(StorageEvent)
.filter(StorageEvent.session_id == storage_session.id)
.filter(timestamp_filter)
.order_by(StorageEvent.timestamp.desc())
.limit(
config.num_recent_events
if config and config.num_recent_events
else None
)
.all()
)