Skip to content

fix(security): 终端转义注入 + legacy token 跨频道 moderator(#372)#374

Merged
leeguooooo merged 1 commit into
mainfrom
fix/372-security
Jul 12, 2026
Merged

fix(security): 终端转义注入 + legacy token 跨频道 moderator(#372)#374
leeguooooo merged 1 commit into
mainfrom
fix/372-security

Conversation

@leeguooooo

Copy link
Copy Markdown
Owner

两条经对抗性验证的安全问题(#372),leo-claude 接管(原 assignee leo-codex-main-dev 的 serve 已死,wake test 证实 offline)。

1. 终端转义注入 — cli/src/format.ts

formatMsg 把远端可控字段原样打进终端。攻击者发一条含终端转义序列的消息,就能在每个 watch/history 该频道的 agent 终端上注入 OSC52 剪贴板写入、用 CSI/CR 伪造或隐藏输出。跨公司频道下是真实横向攻击面。

修复:新增 stripTerminalControls(),在 formatMsg 唯一出口剥离 C0(保留 \t/\n,去掉含 ESC/BEL/CR 的其余)、DEL、C1,一个 choke point 覆盖 body/name/owner/context/attachment 所有远端字段,把注入序列降级为可见文本(内容不丢)。

2. legacy ap_ token 跨频道恒判 moderator — worker/src/acl.ts

owner=null 的存量 ap_ token(迁移 0003 只 ADD COLUMN 不回填 + JS undefined==null)对任意频道(含账号拥有的私有频道)恒判 moderator,可编辑 charter/踢人/归档/reset-guard,作用域全局跨频道。

修复legacyAdminAppliesTo(identity, channel) = legacy token channel.owner_account == null。放行只对无归属账号的老频道生效;账号拥有的频道落到账号/成员规则(legacy token 的 account 为 null,不匹配 owner_account)→ 被拒。channel-scoped token 不受影响(先被 scope 拦)。acl.spec.ts 里原本编码漏洞行为的断言已更新为安全行为。

验证

  • worker:73 文件 / 484 用例全过(含更新后的 acl 对抗断言)、tsc 干净
  • cli:659 用例全过(含 4 个新增控制字符剥离测试)、tsc 干净

Closes #372
https://claude.ai/code/session_01PgxkZeqJmDge3dYe9W2tPZ

两条经对抗性验证的安全问题:

1) 终端转义注入(cli/src/format.ts):formatMsg 把远端可控字段(body/
   name/owner/context/attachment 等)原样打进终端,攻击者发含 OSC52/CSI/CR
   的消息即可在每个 watch/history 该频道的 agent 终端上写剪贴板、伪造/隐藏
   输出。新增 stripTerminalControls 在唯一出口剥离 C0(留 \t\n)/DEL/C1,把
   注入序列降级为可见文本;覆盖所有远端字段。

2) legacy ap_ token 跨频道恒判 moderator(worker/src/acl.ts):owner=null 的
   存量 token(迁移 0003 未回填 + undefined==null)对任意频道恒 moderator,
   可编辑 charter/踢人/归档私有频道。收紧 legacyAdminAppliesTo:放行只对
   owner_account=null 的老频道生效,账号拥有的频道落到账号/成员规则→被拒。
   acl.spec 原本编码的是漏洞行为,已更新为安全断言。

验证:worker 73 文件 484 用例全过、cli 659 过、双 typecheck 干净。

Closes #372

Claude-Session: https://claude.ai/code/session_01PgxkZeqJmDge3dYe9W2tPZ
@leeguooooo leeguooooo merged commit 77906b3 into main Jul 12, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[安全] 跨 agent 终端转义注入(format.ts 原样打印消息体) + legacy ap_ token 跨频道恒判 moderator(acl.ts)

1 participant