Skip to content
Merged
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
6 changes: 5 additions & 1 deletion astrbot/dashboard/services/chat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,11 @@ async def get_sessions_from_dashboard_query(

async def get_session(self, username: str, session_id: str) -> dict:
session = await self.db.get_platform_session_by_id(session_id)
platform_id = session.platform_id if session else "webchat"
if not session:
raise ChatServiceError(f"Session {session_id} not found")
if session.creator != username:
raise ChatServiceError("Permission denied")
platform_id = session.platform_id

project_info = await self.db.get_project_by_session(
session_id=session_id, creator=username
Expand Down
45 changes: 45 additions & 0 deletions tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,51 @@ async def _should_not_call_single_lookup(session_id: str):
assert called["batch_lookup_count"] == 1


@pytest.mark.asyncio
@pytest.mark.parametrize(
"path_template",
[
"/api/chat/get_session?session_id={session_id}",
"/api/v1/chat/sessions/{session_id}",
],
)
async def test_get_chat_session_rejects_session_owned_by_another_user(
app: FastAPIAppAdapter,
authenticated_header: dict,
core_lifecycle_td: AstrBotCoreLifecycle,
path_template: str,
):
test_client = app.test_client()
session_id = f"foreign_get_session_{uuid.uuid4().hex[:8]}"
await core_lifecycle_td.db.create_platform_session(
creator="not_dashboard_user",
platform_id="webchat",
session_id=session_id,
display_name="Foreign Session",
is_group=0,
)
await core_lifecycle_td.platform_message_history_manager.insert(
platform_id="webchat",
user_id=session_id,
content={
"type": "user",
"message": [{"type": "text", "text": "foreign session secret"}],
},
sender_id="not_dashboard_user",
sender_name="not_dashboard_user",
)

response = await test_client.get(
path_template.format(session_id=session_id),
headers=authenticated_header,
)

assert response.status_code == 200
data = await response.get_json()
assert data["status"] == "error"
assert data["message"] == "Permission denied"


@pytest.mark.asyncio
async def test_plugins(
app: FastAPIAppAdapter,
Expand Down
Loading