Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(permissions): 对链接解析暴露的新目标保留真实路径审核
Dash07e4ca3d49fa
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.tsindex 290630ded3..c4a23d767c 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts@@ -3079,6 +3079,61 @@ describe('installation-bound directory grant memory', () => {});describe('Host Auto review', () => {+ it.each(['dir', 'saveDir'] as const)('%s keeps native approval for an unchanged canonical target', async (lane) => {+ const canonical = fs.realpathSync.native(outsideDir);+ const reviewAction = vi.fn(async () => ({ verdict: 'block' as const }));+ liveGrantStateMock.mockReturnValue({ permissionMode: 'auto', remoteHostId: null,+ autoReviewOwner: 'native', isCurrent: () => true, reviewAction });+ expect(await makeDeps('codex').callGhostTool({ ghostId: 'art', tool: 'run', args: {}, [lane]: canonical })).toMatchObject({ ok: true });+ expect(reviewAction).not.toHaveBeenCalled();+ expect(dispatchMock).toHaveBeenCalledOnce();+ });++ it('reviews a Host canonical path when the original harness target is unknown', async () => {+ const reviewAction = vi.fn(async () => ({ verdict: 'block' as const }));+ liveGrantStateMock.mockReturnValue({ permissionMode: 'auto', remoteHostId: null,+ autoReviewOwner: 'native', isCurrent: () => true, reviewAction });+ expect(await authorizeDesktopSessionPath({ sessionId: 's1', sessionInstanceId: 's1-instance',+ workingDir: WORKDIR, path: fs.realpathSync.native(outsideDir), toolName: 'computer.read', operation: 'read',+ }, liveGrantStateMock)).toMatchObject({ allowed: false });+ expect(reviewAction).toHaveBeenCalledOnce();+ });++ // PR #6731: native approval saw the alias, not the canonical outside target.+ // Existing owner tests use direct paths and cannot detect this scope change.+ // Unit: exercise real symlink resolution through each production handoff entry.+ it.each(['dir', 'saveDir', 'attachments', 'forge'] as const)('%s reviews a resolved outside target hidden by a symlink', async (lane) => {+ const workspace = fs.mkdtempSync(path.join(tmpUserData, 'native-workspace-'));+ const target = path.join(outsideDir, lane === 'attachments' ? 'secret.png' : `native-${lane}`);+ if (lane === 'attachments') fs.writeFileSync(target, 'private');+ else fs.mkdirSync(target, { recursive: true });+ const aliasDir = path.join(workspace, 'link');+ fs.symlinkSync(lane === 'attachments' ? outsideDir : target, aliasDir, process.platform === 'win32' ? 'junction' : 'dir');+ const alias = lane === 'attachments' ? path.join(aliasDir, 'secret.png') : aliasDir;+ const canonical = fs.realpathSync.native(target);+ const reviewAction = vi.fn(async (_action: { description?: string }) => ({ verdict: 'block' as const, reason: 'outside target is unauthorized' }));+ liveGrantStateMock.mockReturnValue({ permissionMode: 'auto', remoteHostId: null,+ autoReviewOwner: 'native', isCurrent: () => true, reviewAction });+ const deps = makeDeps('codex', `native-alias-${lane}`);+ alsSessionContextMock.mockReturnValue({ agentKind: 'codex', workingDir: workspace,+ sessionId: `native-alias-${lane}`, sessionInstanceId: `native-alias-${lane}-instance` });+ sessionSnapshotMock.mockResolvedValue({ workingDir: workspace, permissionMode: 'auto', planModeEnabled: false, remoteHostId: null });+ const actual = await vi.importActual<typeof import('../../cindy-brain/ghostLocalPathGrant')>('../../cindy-brain/ghostLocalPathGrant');+ classifyLocalAttachmentPathMock.mockImplementation(actual.classifyLocalAttachmentPath);+ const result = lane === 'forge'+ ? await deps.forgePack({ dir: alias })+ : await deps.callGhostTool({ ghostId: 'art', tool: 'run', args: {},+ ...(lane === 'attachments' ? { attachments: [alias] } : { [lane]: alias }) });+ expect(result).toMatchObject({ ok: false });+ expect(reviewAction).toHaveBeenCalledOnce();+ expect(JSON.parse(reviewAction.mock.calls[0]![0].description!)).toMatchObject({ input: { files: [{ absPath: canonical }] } });+ expect(dirDepositMock).not.toHaveBeenCalled();+ expect(saveDepositMock).not.toHaveBeenCalled();+ expect(grantAttachmentsMock).not.toHaveBeenCalled();+ expect(packGhostDirMock).not.toHaveBeenCalled();+ expect(dispatchMock).not.toHaveBeenCalled();+ });+it.each(['bypassPermissions', 'auto', 'ask'].flatMap((permissionMode) =>[false, true].map((grantOnly) => ({ permissionMode, grantOnly })),))('$permissionMode / grant_only=$grantOnly 在最终授权记账前再次复核', async ({ permissionMode, grantOnly }) => {diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.tsindex 721f7de986..2261d51adb 100644--- a/apps/desktop/src/main/mcp-integrations/ghost.ts+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts@@ -294,6 +294,7 @@ async function authorizeForgeOutsideWorkdir(params: {sessionId: live.sessionId,sessionInstanceId: live.sessionInstanceId,lane: 'forge_source',+ requiresResolvedPathReview: path.relative(path.resolve(params.dir), authorizedDir) !== '',items: [{name: path.basename(authorizedDir) || authorizedDir,absPath: authorizedDir,@@ -362,6 +363,9 @@ export async function authorizeDesktopSessionPath(sessionId: live.sessionId,sessionInstanceId: live.sessionInstanceId,lane: 'outside_workdir',+ // This Host callback receives only a canonical path, without the original+ // harness arguments. Native ownership cannot prove it reviewed this target.+ requiresResolvedPathReview: true,items: [{name: path.basename(request.path) || request.path,absPath: request.path,@@ -684,6 +688,8 @@ async function requestGrantConfirm(params: {sessionInstanceId: string | null;lane: GhostGrantLane;items: GhostGrantFileItem[];+ /** Native approval of an alias does not authorize a newly resolved target. */+ requiresResolvedPathReview?: boolean;toolName?: string;operation?: 'read' | 'write';getLiveSessionGrantState?: CindyGhostsHostDeps['getLiveSessionGrantState'];@@ -719,7 +725,7 @@ async function requestGrantConfirm(params: {// The harness already owns this MCP invocation. Keep live authority and// path/slot checks, but do not ask a second model to reinterpret its intent.// A remote task cannot extend approval to controller-local files.- if (live.autoReviewOwner === 'native' && !live.remoteHostId && live.isCurrent?.() === true && isCurrent?.() === true) {+ if (!params.requiresResolvedPathReview && live.autoReviewOwner === 'native' && !live.remoteHostId && live.isCurrent?.() === true && isCurrent?.() === true) {log.debug('ghost grant: native reviewer owns handoff', { lane: params.lane });return { ok: true, approvalSource: 'auto-review', isCurrent };}@@ -1027,6 +1033,7 @@ async function prepareLocalPathAttachments(params: {sessionInstanceId: params.sessionInstanceId,lane: 'attachments',items,+ requiresResolvedPathReview: needConfirm.some((item) => path.relative(path.resolve(item.url), item.absPath) !== ''),getLiveSessionGrantState: params.getLiveSessionGrantState,});if (!confirm.ok) return confirm;@@ -1140,6 +1147,7 @@ async function confirmDepositOutsideWorkdir(params: {sessionInstanceId: params.sessionInstanceId,lane: params.lane,items: [item],+ requiresResolvedPathReview: path.relative(path.resolve(params.dirAbs), real) !== '',getLiveSessionGrantState: params.getLiveSessionGrantState,});if (!confirm.ok) return confirm;diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.mdindex 8b92fdb71a..72f49287f0 100644--- a/docs/dev-rules/maker-core-and-agent-behavior.md+++ b/docs/dev-rules/maker-core-and-agent-behavior.md@@ -490,6 +490,8 @@ Auto 优先效率,定位是防止严重后果,不是第二次任务规划或原生审批已接管的本地工具调用不叠加 Cindy 模型复审,以 Handle 的实时`getAutoReviewOwner()` 为准;Codex Guardian 故障切换后恢复 Cindy 负责。+路径解析暴露不同目标时,由 Cindy 审核 canonical 路径;只有 canonical 路径、+无法核对原始参数的 Host 回调不享受免复审。Claude MCP/额外目录等现有回退路径仍由 Cindy 审批,不因有订阅而免审。原生明确拒绝不触发第二次模型判断。独立 Host 操作继续使用自身审批入口。diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.mdindex d65db3abb7..a4e019bb33 100644--- a/docs/dev-rules/plugin-security-and-authoring.md+++ b/docs/dev-rules/plugin-security-and-authoring.md@@ -499,7 +499,9 @@ Library 请求同时绑定迁移代次和安装批准,根解析、排队及开`ghost_call` 的 `attachments`/`dir`/`save_dir` 在目标位于 workdir 外时,普通权限档仍沿用现有确认与授权记忆策略;Auto 只有一个审批负责人:本地活跃 Harness 已用原生审批接管工具调用时,交接不再调用 Cindy 模型复审;以运行时 `autoReviewOwner` 为准,- 不从订阅、模型名或数据库快照推断。没有原生接管时才交 Cindy 审阅器,+ 不从订阅、模型名或数据库快照推断。免复审要求原始路径与 canonical 目标一致;+ symlink/junction 解析改变目标时,由 Cindy 审核真实路径。仅接收 canonical 路径、+ 无法核对原始工具参数的 Host 文件系统回调同样保留审核。没有原生接管时交 Cindy 审阅器,allow 逐次放行、block 返回原因、ask 或服务故障才交用户确认。Full Access 旁路则仅当Host 能现读到**本地活跃会话**的运行时权限恰为`bypassPermissions`(Full Access)时自动批准。该判定不得读取启动期 MCP context 快照,