#846·kotaemon

跨用户对话 IDOR -- 未授权读取和已授权删除任何对话

作者: geo-chen创建于 2026年7月3日更新于 2026年7月3日
标签bug

根本原因 - 缺少在 select_conv 中的所有权检查:

libs/ktem/ktem/pages/chat/control.py 中,函数 select_conv(第 299 行):

python
def select_conv(self, conversation_id, user_id):
    with Session(engine) as session:
        statement = select(Conversation).where(Conversation.id == conversation_id)
        try:
            result = session.exec(statement).one()
            id_ = result.id
            name = result.name
            # ...
            if user_id == result.user:
                selected = result.data_source.get("selected", {})
            else:
                selected = {}
            # NO EARLY RETURN -- chats are returned regardless of user_id
            chats = result.data_source.get("messages", [])

该函数通过 ID 获取任何对话,并返回其消息,即使 user_id 不匹配 result.user。所有权检查的唯一影响是,对于非所有者,selected(文件选择器状态)为空;而聊天消息本身总是返回。

内容来源: Cinnamon/kotaemon