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。

feat(plugin): 开放 macOS Node 插件的底层权限能力 (#6029)

GaoWei Liu6dc19ee18bde
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/nodeRuntimeBroker.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/nodeRuntimeBroker.test.ts
index ca4e1426a3..1afb0b5c86 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/nodeRuntimeBroker.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/nodeRuntimeBroker.test.ts
@@ -2,6 +2,7 @@
import { EventEmitter } from 'node:events';
import os from 'node:os';
+import path from 'node:path';
import { PassThrough } from 'node:stream';
import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -412,6 +413,50 @@ afterEach(() => {
});
describe('nodeRuntimeBroker · Electron utilityProcess 适配', () => {
+ describe.each(['darwin', 'win32', 'linux'] as const)('%s 系统权限责任归属', (platform) => {
+ it.each([
+ { mode: '普通工作进程', childArgs: undefined },
+ { mode: '宿主代启子进程', childArgs: ['--probe'] },
+ ])('$mode 保留平台对应的启动策略', ({ childArgs }) => {
+ const platformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform')!;
+ const child = new FakeUtilityProcess();
+ const fork = vi.fn((modulePath: unknown, entryArgs: unknown, options: unknown) => {
+ void modulePath;
+ void entryArgs;
+ void options;
+ return child;
+ });
+ const pluginDir = path.join(os.tmpdir(), 'demo');
+ let worker: NodeWorkerProcess | undefined;
+
+ try {
+ Object.defineProperty(process, 'platform', { ...platformDescriptor, value: platform });
+ worker = createUtilityNodeWorkerProcess(
+ path.join(pluginDir, 'worker.cjs'),
+ pluginDir,
+ 'demo',
+ fork as never,
+ childArgs,
+ );
+
+ expect(fork).toHaveBeenCalledOnce();
+ const options = fork.mock.calls[0][2];
+ expect(options).toHaveProperty(
+ 'serviceName',
+ `cindy-ghost-node:demo${childArgs === undefined ? '' : ':child'}`,
+ );
+ if (platform === 'darwin') {
+ expect(options).toHaveProperty('disclaim', false);
+ } else {
+ expect(options).not.toHaveProperty('disclaim');
+ }
+ } finally {
+ Object.defineProperty(process, 'platform', platformDescriptor);
+ worker?.kill();
+ }
+ });
+ });
+
it('不依赖 RunAsNode,过滤宿主秘密,并只用 parentPort 推送 stdin', () => {
vi.stubEnv('PATH', '/usr/bin');
vi.stubEnv('NODE_OPTIONS', '--inspect=0.0.0.0:9229');
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index d878d4f075..8df079df2f 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -4278,6 +4278,9 @@ MCP server 的 sampling / elicitation / roots 等 server→client 反向请求
- **最重要的安全事实**:Node 进程不是浏览器沙箱,它拥有当前登录系统账号能拿到的
本机权限,能读写文件、联网、起别的进程。Cindy 会在插件详情中显著展示这项能力,
但安装不会追加确认弹窗;不需要本机能力的插件不要声明 node,用户也只应安装可信来源。
+- macOS 的 Node 工作进程及宿主代启的 Node 子进程保留 Cindy 的系统权限责任归属,
+ 可在系统允许范围内使用 Cindy 已获得的系统授权。尚未取得的权限仍由系统决定是否需要
+ 授权;原生子进程的签名与用途声明也会影响结果。这不额外开放 Cindy IPC 或托管凭证。
### 4.12.4 宿主代启子进程(childSpawn)
diff --git a/apps/desktop/src/main/cindy-brain/nodeRuntimeBroker.ts b/apps/desktop/src/main/cindy-brain/nodeRuntimeBroker.ts
index 3408cf6515..692ece8696 100644
--- a/apps/desktop/src/main/cindy-brain/nodeRuntimeBroker.ts
+++ b/apps/desktop/src/main/cindy-brain/nodeRuntimeBroker.ts
@@ -519,7 +519,9 @@ export function createUtilityNodeWorkerProcess(
env,
stdio: ['ignore', 'pipe', 'pipe'],
serviceName: `cindy-ghost-node:${ghostId}${isChild ? ':child' : ''}`,
- ...(process.platform === 'darwin' ? { disclaim: true } : {}),
+ // 参考 VS Code 的本地扩展模型,为插件开放底层系统能力:
+ // 保留宿主的 macOS TCC 责任归属,实际访问仍由系统权限决定。
+ ...(process.platform === 'darwin' ? { disclaim: false } : {}),
});
const stdout = child.stdout;
const stderr = child.stderr;
diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.md
index caf715555c..5569af6bd1 100644
--- a/docs/dev-rules/plugin-security-and-authoring.md
+++ b/docs/dev-rules/plugin-security-and-authoring.md
@@ -171,6 +171,12 @@ Library 请求同时绑定迁移代次和安装批准,根解析、排队及开
- 主机按 `webContents` 绑定反查真实 ghostId,**不信任 sender 自报身份**。
- 沉睡、抽离和主机退出必须终止对应沙箱;沙箱崩溃只由 `GhostRuntime` 收敛,不得带崩
主应用。
+- 声明 `node` 的插件另有独立 Node 工作进程,拥有当前系统用户级本机能力,不属于
+ 上述浏览器沙箱。参考 [VS Code 的本地扩展权限模型](https://code.visualstudio.com/docs/configure/extensions/extension-runtime-security),
+ macOS 以 `disclaim: false` 创建插件 Node 工作进程及宿主代启的 Node 子进程,保留
+ 宿主的 TCC 责任归属,为插件开放底层系统能力;具体访问仍由系统授权、签名和用途声明
+ 决定,不自动授予宿主尚未取得的权限。实现见 `nodeRuntimeBroker.ts` 的
+ `createUtilityNodeWorkerProcess`。浏览器沙箱、Host 能力守门和宿主环境变量过滤继续生效。
## 3. 权限即授权边界