Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(wechat): keep companion guest approvals with owner

Chris8e29c83cc979
diff --git a/apps/desktop/src/main/im/wechat/WechatIM.ts b/apps/desktop/src/main/im/wechat/WechatIM.ts
index e9aede8132..a4eb3c3514 100644
--- a/apps/desktop/src/main/im/wechat/WechatIM.ts
+++ b/apps/desktop/src/main/im/wechat/WechatIM.ts
@@ -527,6 +527,15 @@ export class WechatIM extends BaseIM implements RichChannelIM {
): Promise<InteractionDecision> {
const shared = options?.sharedPermission;
if (shared?.decision) return shared.result;
+ if (request.kind === 'permission'
+ && this.#turnRuntime?.runner.companionBotIdFor?.(this.#epoch?.credentials.ilinkBotId ?? '')
+ && !this.isOwner(userId)) {
+ // The router already mirrors permissions to the owner's Desktop/mobile.
+ // A guest must never receive a prompt or a pending WeChat reply slot.
+ // The shared route owns cancellation/timeout; without it, fail closed.
+ return shared ? shared.result
+ : defaultWechatInteractionDecision(request, 'desktop_confirmation_not_installed');
+ }
const previous = this.#pendingInteractions.get(userId);
if (previous) {
clearTimeout(previous.timer);
diff --git a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
index 209be0d506..bafd1096a2 100644
--- a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
+++ b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
@@ -8,6 +8,10 @@ import {
} from '@cindy/wechat-ilink';
import type { DbClient } from '../../../localDb/client/DbClient';
+import {
+ beginInteractionRoute, installDesktopInteractionHandler, requestHostInteraction,
+} from '../../../maker-ipc/interactionRouter';
+import type { SharedPermission } from '../../../maker-ipc/sharedPermission';
import { __testing, sessionIdFor, WechatIM, type WechatIMDeps } from '../WechatIM';
const mediaMocks = vi.hoisted(() => ({
@@ -329,6 +333,67 @@ describe('WechatIM host boundary', () => {
});
});
+ // PR #6492 security regression (unit): existing text parser tests did not exercise
+ // a companion guest asking for a tool permission. Use the real router + adapter:
+ // no guest prompt/reply slot, owner decision wins, missing owner surface times out.
+ it.each([true, false])('keeps guest tool approval on the owner surface (available=%s)', async (hasDesktop) => {
+ const im = new WechatIM(deps());
+ im.attachTurnRuntime({ runner: { companionBotIdFor: () => 'cindy' } } as never);
+ const send = vi.spyOn(im, 'sendText').mockResolvedValue({ messageId: 'prompt' });
+ const session = { id: 'guest-lane', setInteractionListener: vi.fn() };
+ const request = { kind: 'permission' as const, requestId: 'guest-write',
+ toolName: 'Write', input: { file_path: '/tmp/guest-write', content: 'guest input' } };
+ let ownerPermission: SharedPermission | undefined;
+ if (hasDesktop) installDesktopInteractionHandler(session, async (_request, shared) => {
+ ownerPermission = shared;
+ return shared!.result;
+ });
+ const lease = beginInteractionRoute(session, {
+ route: { sessionId: session.id, turnId: 'turn', origin: { kind: 'im', channel: 'wechat' },
+ interactionSurface: 'channel-card', requesterAuthority: 'guest', timeoutMs: 1_000 },
+ handle: (req, sharedPermission) => im.handleTextInteraction('guest', req, { sharedPermission }),
+ });
+ vi.useFakeTimers();
+ try {
+ const pending = requestHostInteraction(session, request, new AbortController().signal);
+ expect(send).not.toHaveBeenCalled();
+ expect(im.cancelTextInteraction('guest', request.requestId,
+ { kind: 'permission', behavior: 'allow' })).toBe(false);
+ if (hasDesktop) {
+ ownerPermission!.decide({ kind: 'permission', behavior: 'allow' });
+ await expect(pending).resolves.toEqual({ kind: 'permission', behavior: 'allow' });
+ } else {
+ await vi.advanceTimersByTimeAsync(1_000);
+ await expect(pending).resolves.toMatchObject({ kind: 'permission', behavior: 'deny', reason: 'interaction_timeout' });
+ await expect(im.handleTextInteraction('guest', request)).resolves.toMatchObject({
+ kind: 'permission', behavior: 'deny', reason: 'desktop_confirmation_not_installed',
+ });
+ }
+ expect(send).not.toHaveBeenCalled();
+ } finally { lease.release(); vi.useRealTimers(); await im.dispose(); }
+ });
+
+ it('retains companion owner WeChat approvals and guest ordinary questions', async () => {
+ const { im } = restoredConnection(() => 0);
+ im.attachTurnRuntime({ runner: { companionBotIdFor: () => 'cindy' } } as never);
+ const send = vi.spyOn(im, 'sendText').mockResolvedValue({ messageId: 'prompt' });
+ await im.init();
+ try {
+ const permission = { kind: 'permission' as const, requestId: 'owner-write', toolName: 'Write', input: {} };
+ const ownerResult = im.handleTextInteraction('owner', permission);
+ expect(send).toHaveBeenCalledWith('owner', expect.stringContaining('允许'));
+ expect(im.cancelTextInteraction('owner', permission.requestId, { kind: 'permission', behavior: 'allow' })).toBe(true);
+ await expect(ownerResult).resolves.toEqual({ kind: 'permission', behavior: 'allow' });
+ const question = { kind: 'ask_user_question' as const, requestId: 'guest-question',
+ questions: [{ question: '选择格式', options: [{ label: '文本' }] }] };
+ const guestResult = im.handleTextInteraction('guest', question);
+ expect(send).toHaveBeenCalledWith('guest', expect.stringContaining('选择格式'));
+ const answer = { kind: 'ask_user_question' as const, answers: { 选择格式: '文本' } };
+ expect(im.cancelTextInteraction('guest', question.requestId, answer)).toBe(true);
+ await expect(guestResult).resolves.toEqual(answer);
+ } finally { await im.dispose(); }
+ });
+
it('fails closed before authorization when the signed compatibility policy disables it', async () => {
const createTransport = vi.fn();
const im = new WechatIM(
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 1ffe82a9b1..bc5636e2b7 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -60,6 +60,7 @@ Telegram 设为全响应的群;设置页的人格与行为配置不带。移
绑定只保存伙伴归属,不复制凭证、不创建第二份轮询。主人私聊进入主任务,其他私聊进入渠道专线。
解除伙伴关联恢复个人微信独立路由,保留微信授权与原工作目录;有排队消息或运行中的任务时拒绝切换。
微信仍沿用渠道的逐轮权限确认约束,模型需为 Claude Code / Codex,权限需为自动审查或询问。
+绑定伙伴后,访客触发的工具权限仅由主人的 Desktop/同账号手机确认;不向访客发送权限提示或接受其授权回复。主人微信确认与访客普通问答保持原有行为。
每条连接一份传输层实例(复用个人 bot 的各渠道适配器,凭证按连接 id 前缀隔离在本机安全存储),
它说什么、记得什么、会什么、用什么模型,全部来自伙伴。主人私聊进该伙伴的 canonical 主任务;每个群 / 话题与
每位外部用户的私聊各一条隐藏的渠道专线 Session(`role = 'channel'`,