Skip to content

[Bug]: agent_space_name() 因缺少分隔符存在哈希碰撞风险 #595

@xudongcc

Description

@xudongcc

Bug Description

概述

UserIdentifier.agent_space_name() 使用 md5(user_id + agent_id)[:12] 计算 agent scope space 名称。
但拼接时 user_id 和 agent_id 之间没有分隔符,存在碰撞风险。

问题

function md5Short(input: string): string {
return createHash("md5").update(input).digest("hex").slice(0, 12);
}

def agent_space_name(self) -> str:

不同的 (user_id, agent_id) 组合可能产生相同的拼接字符串,从而得到相同的哈希值:

这意味着不同的用户/Agent 组合可能映射到同一个 agent scope space,导致意外的数据共享或覆盖(memories、skills、instructions、workspaces)。

建议修复

在拼接中加入 user_idagent_id 中不允许出现的分隔符(两者限制为 [a-zA-Z0-9_-]):

def agent_space_name(self) -> str:
    return hashlib.md5(f"{self._user_id}@{self._agent_id}".encode()).hexdigest()[:12]

或者直接使用可读格式,便于调试:

def agent_space_name(self) -> str:
    return f"{self._user_id}@{self._agent_id}"

注意: 以上任一方案都是破坏性变更,现有数据将无法直接读取。可能需要迁移工具或向后兼容查找逻辑。

Steps to Reproduce

创建两个用户/Agent 组合使其 user_id + agent_id 拼接结果相同(如 user_id="alice", agent_id="bot" 与 user_id="aliceb", agent_id="ot"),观察 agent_space_name() 返回值。

Expected Behavior

不同的 (user_id, agent_id) 组合应映射到不同的 agent scope space,数据互相隔离。

Actual Behavior

拼接缺少分隔符,上述两个组合生成相同的哈希值,共享同一个 agent scope space,可能导致数据互相覆盖。

Minimal Reproducible Example

Error Logs

OpenViking Version

0.2.5

Python Version

3.10.0

Operating System

macOS

Model Backend

None

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions