Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(main): 通知 handler 先校验 IPC 来源,再读 renderer 自报的通道与免打扰豁免
WZBbiao3318650f3715
diff --git a/apps/desktop/src/main/__tests__/notificationService.test.ts b/apps/desktop/src/main/__tests__/notificationService.test.tsindex 14fffe7cca..5e9f3278cd 100644--- a/apps/desktop/src/main/__tests__/notificationService.test.ts+++ b/apps/desktop/src/main/__tests__/notificationService.test.ts@@ -102,6 +102,13 @@ vi.mock('../appBadgeService', () => ({markSessionNeedsAttention,}));+// 高权限 IPC 的入站来源断言:真实实现要 BrowserWindow 与 app-content 登记表,+// 这里只验它在该 handler 上被调到(且在任何副作用之前)。+const assertTrustedAppRendererEvent = vi.fn((_event: unknown): void => {});+vi.mock('../security/trustedAppRenderer', () => ({+ assertTrustedAppRendererEvent: (event: unknown) => assertTrustedAppRendererEvent(event),+}));+// 「消息免打扰」判定:真实实现读账号库的同步索引,这里只验 handler 在哪个时刻用它。const isSessionNotificationsMutedSync = vi.fn((_sessionId: string): boolean => false);vi.mock('../localDb/sessionFlagRegistry', () => ({@@ -171,6 +178,7 @@ async function freshService() {ownerScopeCurrent = true;ownerScopeKey = 'account-a:1';markSessionNeedsAttention.mockClear();+ assertTrustedAppRendererEvent.mockReset();isSessionNotificationsMutedSync.mockReset().mockReturnValue(false);sendMobileSessionNotify.mockReset().mockReturnValue(true);getMobileNotifyGeneration.mockClear();@@ -532,6 +540,30 @@ describe('notificationService — channels 分发', () => {.rejects.toThrow('invalid session event payload');});+ it('rejects a caller that is not the Cindy renderer before any channel or badge work', async () => {+ const { initNotificationService } = await freshService();+ initNotificationService(baseDeps(makeFeishuIm('ou_owner')));+ // 插件 webview 等其它 webContents 能调到同一个 channel:来源断言失败时+ // 不得记角标,也不得把 title/kind 经飞书或手机送出去。+ assertTrustedAppRendererEvent.mockImplementationOnce(() => {+ throw new Error('PERMISSION_DENIED');+ });++ await expect(+ invokeHandler({+ sessionId: 's1',+ title: 'Fix login',+ kind: 'done',+ channels: { desktop: true, feishu: true, mobile: true },+ }),+ ).rejects.toThrow('PERMISSION_DENIED');++ expect(assertTrustedAppRendererEvent).toHaveBeenCalledTimes(1);+ expect(markSessionNeedsAttention).not.toHaveBeenCalled();+ expect(notificationCtor).not.toHaveBeenCalled();+ expect(sendMobileSessionNotify).not.toHaveBeenCalled();+ });+it('does not treat a pre-drain running snapshot as a reason to lose the completion fallback', async () => {const { initNotificationService } = await freshService();initNotificationService(baseDeps(makeFeishuIm('owner')));diff --git a/apps/desktop/src/main/notificationService.ts b/apps/desktop/src/main/notificationService.tsindex 501a25e363..c7f5eaa4de 100644--- a/apps/desktop/src/main/notificationService.ts+++ b/apps/desktop/src/main/notificationService.ts@@ -34,6 +34,7 @@ import { isSessionNotificationsMutedSync } from './localDb/sessionFlagRegistry';import type { ChatMessageNotification } from './maker-ipc/chatMessageNotifications';import { readSessionNotificationPreview, type SessionNotificationPreview } from './localDb/sessionNotificationPreview';import { drainSessionActiveTurnWrites, getSessionNotificationTurnSignal } from './localDb/sessionActiveTurn';+import { assertTrustedAppRendererEvent } from './security/trustedAppRenderer';import { captureDataOwnerBroadcastScope, isDataOwnerBroadcastScopeCurrent } from './device-link/broadcast-tap';import { drainPersistQueue } from './messagePersistBroadcaster';import { createLogger } from './logger';@@ -251,7 +252,10 @@ export function initNotificationService(deps: NotificationServiceDeps): void {ipcMain.handle('notification:show-session-event',- async (_event, payload: ShowSessionEventPayload): Promise<void> => {+ async (event, payload: ShowSessionEventPayload): Promise<void> => {+ // 这条 handler 的 channels / markAttention 全由 renderer 自报,先验来源:只认 Cindy+ // 自有顶层 renderer(插件 webview 等其它 webContents 一律 PERMISSION_DENIED)。+ assertTrustedAppRendererEvent(event);// renderer payload 不可信:mobile 通道会把 title/kind 送出本机(经 relay/APNs),// main 必须做运行时形状校验,TS 类型不算(electron-security 规则)。正文摘要// 不来自 renderer(main 侧读库),relay 有 per-user 频控、main 侧另有 5s@@ -274,6 +278,8 @@ export function initNotificationService(deps: NotificationServiceDeps): void {// 「消息免打扰」任务不再走任何外向提醒通道(系统 toast / 灵动岛 / 手机 / 飞书);// 未读与角标已在上一行照常记账,任务内的提醒不受影响。静音标记属于本机那行任务,// 其它设备的任务(markAttention === false)可能与本机有同 id 的无关任务行,不查。+ // main 没有远端任务的权威映射(device-link 镜像在 renderer),这一位仍由 renderer 报,+ // 来源边界靠上面那道 assertTrustedAppRendererEvent。if (markAttention && isSessionNotificationsMutedSync(sessionId)) return;// Content is read from main's transcript. Bound only enrichment, not delivery;