Skip to content

[BUG] MCP 接口 mcp_start/mcp_question 跨工作空间存储问数记录导致数据泄露 #1221

Description

@Fit111

SQLBot Version
1.9.0 专业版
Run Mode
离线安装包

Describe the bug
通过 MCP 接口 mcp_start + mcp_question 进行问数时,即使 mcp_question 显式传入了目标工作空间的 oid,问数记录仍会写入 mcp_start 创建会话时的工作空间,导致跨工作空间数据泄露。
具体表现:

  • 同一用户同时属于工作空间 A、B
  • 用户最后在 A 空间登录(sys_user.oid = A
  • 调用 mcp_start 后,再调用 mcp_question 并传入 oid=B
  • 问数内容实际按 B 空间的数据源/术语库处理,但 chat 表的 oid 仍为 A
  • 在 SQLBot UI 切换到工作空间 A 时,能看到本属于 B 空间的问数记录
  • A 空间可能没有对应数据源,记录内容明显「串空间」
    数据库查证:chat.oid 为 A,但 chat_record 中的 question/SQL/datasource 属于 B 空间。

可以看到 华北大区 工作空间下有一条问数记录
Image

但是此工作空间并没有数据源
Image

To Reproduce

前置条件

  1. 同一用户 testuser 同时加入工作空间 A(oid=1)和 B(oid=2)
  2. B 空间有数据源(如「车辆信息」),A 空间无该数据源或数据源不同
  3. 用户最后在 A 空间登录(sys_user.oid = 1

复现步骤

  1. 调用 mcp_start 创建会话(此时 chat.oid 被固定为 sys_user.oid,即 A)
    POST /api/v1/mcp/mcp_start
    {
      "username": "testuser",
      "password": "xxx"
    }

返回:{"access_token": "...", "chat_id": 100}

  1. 调用 mcp_question,显式传入 B 空间 oid

POST /api/v1/mcp/mcp_question
{
"token": "<access_token>",
"chat_id": 100,
"question": "查询B空间某表的总数",
"oid": "2",
"stream": false
}
3. 在数据库中查询
SELECT id, oid, create_by, brief, datasource FROM chat WHERE id = 100;
-- 结果:oid = 1(A 空间)
SELECT cr.id, cr.chat_id, cr.question, cr.datasource, cr.sql
FROM chat_record cr WHERE cr.chat_id = 100;
-- 结果:datasource/SQL 属于 oid=2(B 空间)

在 SQLBot UI 切换到工作空间 A,打开问数列表

能看到 chat_id=100 的会话
内容为 B 空间的问数结果

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions