Repository navigation
fix(lark): oncall talk 权限按接收 bot 隔离 - #91
Merged
deepcoldy merged 1 commit intoJun 2, 2026
Merged
Conversation
Owner
|
感谢 @xiongz-c 的修复 🙏 这个 PR 堵了一个真实的跨 bot 权限泄漏:之前任一 bot 把群绑成 oncall,同群里的 sibling bot 也会跟着对全员开放 talk,等于一个 bot 的 oncall 配置泄漏成了另一个 bot 的 talk 权限。 Review 结论 clean、无阻断。已实测验证:
已审核通过,合并到 master。 |
deepcoldy
approved these changes
Jun 2, 2026
deepcoldy
left a comment
Owner
There was a problem hiding this comment.
Reviewed in an isolated worktree + mutation-tested the fix. Clean, no blockers. 详见 PR 评论。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景 / 现象
botmux 支持在同一部署里运行多个 Lark bot。每个 bot 都有自己的
allowedUsers、chatGrants/globalGrants和oncallChats,因此/oncall bind的 talk 放行也应该按 bot 隔离。当前
evaluateTalk()的 oncall 判断用了isChatOncallBoundForAnyBot(chatId):只要同部署里任意一个 bot 绑定了某个 oncall 群,当前接收消息的 bot 就会把这个群视为 oncall 并放开 talk。这会导致多 bot 部署下的权限串扰:
oc_xxx作为 oncall 群oc_xxx,并且有自己的allowedUsers/ grants 限制oc_xxx里 @ Bot B 时,Bot B 也会因为 Bot A 的 oncall 绑定而通过canTalk结果是 Bot A 的 oncall 配置放开了 sibling Bot B 的 talk 权限,绕过了 Bot B 自己的
allowedUsers、chatGrants、globalGrants。根因
isChatOncallBoundForAnyBot()/findOncallChatForAnyBot()是跨 bot discovery:它会查当前 bot,也会从共享bots.json里发现 sibling bot 的 oncall 绑定。这个跨 bot lookup 适合用于部署级发现/继承场景,例如 pinned working dir、default-oncall 之类;但把它放进 talk 授权闸门后,就把 per-bot 的
/oncall bind语义扩大成了 deployment-wide talk 放行。同样的问题也存在于 foreign bot @mention 的 chat-scope fast path:外部 bot 只要命中任意 sibling 的 oncall 绑定,就能跳过接收侧的 peer / grant vetting。
修复
src/im/lark/event-dispatcher.ts改为 importfindOncallChatevaluateTalk(larkAppId, chatId, senderOpenId)中,oncall talk gate 改成findOncallChat(larkAppId, chatId)findOncallChat(larkAppId, chatId)/oncall bind不会放开 sibling bot;如果 sibling bot 也要开放,需要自己绑定同一个 chatfindOncallChatForAnyBot()/isChatOncallBoundForAnyBot(),因为其他路径仍需要跨 bot oncall discovery回归覆盖
新增/更新测试覆盖这个权限边界:
oc_shared_oncallcanTalk(A) === truecanTalk(B) === falsecanTalk(B) === true验证
pnpm vitest run test/grant-gates.test.ts test/event-dispatcher.test.ts:87 tests 通过pnpm vitest run test/event-dispatcher.test.ts test/grant-gates.test.ts test/bot-registry.test.ts:123 tests 通过pnpm build:通过影响范围
只收紧 oncall talk 授权和 foreign bot chat-scope gate 的接收侧判断。
跨 bot oncall discovery 函数仍保留,其他需要 deployment-wide discovery 的代码路径不受影响。