Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-desktop): 校验本地控制授权入口并明确安全边界
Dashae206378288e
diff --git a/apps/desktop/src/main/device-link/__tests__/mirrorCacheIpcBoundary.test.ts b/apps/desktop/src/main/device-link/__tests__/mirrorCacheIpcBoundary.test.tsindex e0166e6f51..03b95fed2c 100644--- a/apps/desktop/src/main/device-link/__tests__/mirrorCacheIpcBoundary.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/mirrorCacheIpcBoundary.test.ts@@ -133,6 +133,15 @@ vi.mock('../subscriptionRefcount', () => ({import { DEVICE_LINK_INVOKE } from '../../../shared/deviceLinkIpc';import { registerDeviceLinkIpc } from '../ipc';+import { REMOTE_INVOKE_ALLOWLIST } from '@cindy/device-link';+import { DESKTOP_LOCAL } from '../../../shared/remoteDesktop';+import {+ setRemoteControlEnabled,+ revokeController,+ restoreController,+ disconnectAllControllers,+} from '../index';+import { setDeviceControlEnabled } from '../settings-store';const EVENT = {} as Electron.IpcMainInvokeEvent;@@ -220,3 +229,52 @@ describe('mirror-cache IPC 授权边界', () => {expect(h.cache.clearAll).not.toHaveBeenCalled();});});++describe('local control authorization IPC boundary', () => {+ const calls = [+ [DEVICE_LINK_INVOKE.SET_ENABLED, true, setRemoteControlEnabled],+ [DEVICE_LINK_INVOKE.SET_ENABLED, false, setRemoteControlEnabled],+ [+ DEVICE_LINK_INVOKE.SET_DEVICE_CONTROL_ENABLED,+ { deviceId: 'peer', enabled: true },+ setDeviceControlEnabled,+ ],+ [+ DEVICE_LINK_INVOKE.SET_DEVICE_CONTROL_ENABLED,+ { deviceId: 'peer', enabled: false },+ setDeviceControlEnabled,+ ],+ [DEVICE_LINK_INVOKE.RESTORE, { deviceId: 'peer' }, restoreController],+ [DEVICE_LINK_INVOKE.REVOKE, { deviceId: 'peer' }, revokeController],+ [DEVICE_LINK_INVOKE.DISCONNECT_ALL, undefined, disconnectAllControllers],+ ] as const;++ it.each(calls)(+ 'rejects foreign senders before %s can change authority',+ async (channel, payload, effect) => {+ h.trusted = false;+ await expect(call(channel, payload)).rejects.toThrow(/PERMISSION_DENIED/);+ expect(effect).not.toHaveBeenCalled();+ },+ );++ it.each(calls)(+ 'keeps %s available to the local app without another confirmation',+ async (channel, payload, effect) => {+ await call(channel, payload);+ expect(effect).toHaveBeenCalledTimes(1);+ },+ );++ it.each(calls)('still requires account capability for %s', async (channel, payload, effect) => {+ h.canUseDeviceLink = false;+ await expect(call(channel, payload)).rejects.toThrow(/PERMISSION_DENIED/);+ expect(effect).not.toHaveBeenCalled();+ });++ it('never exposes local grants, revocation or capture IPC to remote invokes', () => {+ for (const channel of [...calls.map(([channel]) => channel), ...Object.values(DESKTOP_LOCAL)]) {+ expect(REMOTE_INVOKE_ALLOWLIST.has(channel), channel).toBe(false);+ }+ });+});diff --git a/apps/desktop/src/main/device-link/ipc.ts b/apps/desktop/src/main/device-link/ipc.tsindex 8ae89b163d..a19813f68e 100644--- a/apps/desktop/src/main/device-link/ipc.ts+++ b/apps/desktop/src/main/device-link/ipc.ts@@ -1250,13 +1250,18 @@ export function registerDeviceLinkIpc(deps: DeviceLinkIpcDeps = defaultDeps()):// Keep the local keep-awake setting available without a Cindy account. The// setting is local-only and does not expose any remote-control capability.ipcMain.handle(DEVICE_LINK_INVOKE.GET_STATE, () => handleGetState(deps));- ipcMain.handle(DEVICE_LINK_INVOKE.SET_ENABLED, (_e, enabled: unknown) =>- gated(handleSetEnabled)(deps, enabled),- );+ ipcMain.handle(DEVICE_LINK_INVOKE.SET_ENABLED, (e, enabled: unknown) => {+ // Account capability does not identify the local page making a grant.+ // This rejects foreign frames; it is not proof of a human click within+ // a compromised app renderer.+ assertTrustedAppRendererEvent(e);+ return gated(handleSetEnabled)(deps, enabled);+ });ipcMain.handle(DEVICE_LINK_INVOKE.SET_KEEP_AWAKE, (_e, enabled: unknown) =>handleSetKeepAwake(deps, enabled),);- ipcMain.handle(DEVICE_LINK_INVOKE.SET_DEVICE_CONTROL_ENABLED, (_e, payload: unknown) => {+ ipcMain.handle(DEVICE_LINK_INVOKE.SET_DEVICE_CONTROL_ENABLED, (e, payload: unknown) => {+ assertTrustedAppRendererEvent(e);requireDeviceLinkCapability();const p = (payload ?? {}) as { deviceId?: unknown; enabled?: unknown };return handleSetDeviceControlEnabled(deps, p.deviceId, p.enabled);@@ -1319,17 +1324,20 @@ export function registerDeviceLinkIpc(deps: DeviceLinkIpcDeps = defaultDeps()):const p = (payload ?? {}) as { deviceId?: unknown; topics?: unknown };return handleUnsubscribe(deps, p.deviceId, p.topics, e.sender.id);});- ipcMain.handle(DEVICE_LINK_INVOKE.DISCONNECT_ALL, () => {+ ipcMain.handle(DEVICE_LINK_INVOKE.DISCONNECT_ALL, (e) => {+ assertTrustedAppRendererEvent(e);requireDeviceLinkCapability();resetSubscriptionRefcount(); // 整体断开 → 清空引用,后续重连各窗口重订阅return handleDisconnectAll(deps);});- ipcMain.handle(DEVICE_LINK_INVOKE.REVOKE, (_e, payload: unknown) => {+ ipcMain.handle(DEVICE_LINK_INVOKE.REVOKE, (e, payload: unknown) => {+ assertTrustedAppRendererEvent(e);requireDeviceLinkCapability();const p = (payload ?? {}) as { deviceId?: unknown };return handleRevoke(deps, p.deviceId);});- ipcMain.handle(DEVICE_LINK_INVOKE.RESTORE, (_e, payload: unknown) => {+ ipcMain.handle(DEVICE_LINK_INVOKE.RESTORE, (e, payload: unknown) => {+ assertTrustedAppRendererEvent(e);requireDeviceLinkCapability();const p = (payload ?? {}) as { deviceId?: unknown };return handleRestore(deps, p.deviceId);diff --git a/docs/remote-desktop.md b/docs/remote-desktop.mdindex abd4ed7cf0..6690b4baac 100644--- a/docs/remote-desktop.md+++ b/docs/remote-desktop.md@@ -52,7 +52,9 @@ Computers without this channel reject it and the phone asks for an upgrade. Scredata and signaling are never added to the generic broadcast allowlist.WebRTC carries a video track and an ordered input DataChannel. Capture runs in-the existing, trusted main renderer, with exact Main-side host identity checks.+a dedicated sandboxed renderer with a narrow preload and exact Main-side host+identity checks. The main application renderer does not receive capture frames+or the capture bridge. Main destroys the capture host when its authority ends.The phone runs a dedicated trusted inline WebView document; the untrusted HTMLpreview's restrictions are unchanged. The mobile presentation module requests scene rotation and a playback audio sessionfor system picture in picture. This requires a new native mobile build. Voice@@ -162,6 +164,25 @@ checked against current authorization. Local stop, revocation, relay loss, peeroffline, display changes, and capture-host loss stop the lease. Stale operationscannot resurrect a stopped lease. Input sequence numbers prevent replay.+### Local UI authority versus compromised application code++Local control switches, controller restoration and revocation require a+registered Cindy application top-level frame. Account capability alone does not+authorize these IPC calls. None of the local remote-desktop or control-grant+channels is available through the remote invoke allowlist. This source check+does not add another confirmation to ordinary settings changes.++These checks authenticate the calling surface, not the person behind each+JavaScript call. They cannot distinguish the legitimate application from+arbitrary JavaScript executing in the same main application frame. That frame+also has existing terminal, file-editing and Agent-control bridges. Capture+isolation and a native confirmation on one switch do not isolate those other+capabilities or protect same-user settings against arbitrary local execution.+The compromised-main-renderer opt-in path remains a security review concern;+the source checks must not be presented as resolving it. Addressing that threat+requires a coordinated application capability boundary, rather than treating+one extra dialog as proof of local human consent.+The native helper holds actual down/up state and releases it on EOF/stop, with awatchdog for an unresponsive parent. Input batches and queues are bounded; abackpressure failure stops control rather than silently dropping key-up events.