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(shared-task): 目录监听只放行任务记录的原样路径,防止访客累积 watcher

david14c7b4eeec24
diff --git a/apps/desktop/src/main/device-link/__tests__/sharedTaskFileAccess.test.ts b/apps/desktop/src/main/device-link/__tests__/sharedTaskFileAccess.test.ts
index c5812f82f8..cd690e412b 100644
--- a/apps/desktop/src/main/device-link/__tests__/sharedTaskFileAccess.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/sharedTaskFileAccess.test.ts
@@ -54,6 +54,17 @@ describe('shared task workdir binding', () => {
expect(denied).toMatchObject({ topics: ['session:task'], verified: new Set() });
});
+ it('rejects alias spellings of the workdir so a guest cannot multiply host watchers', async () => {
+ const aliases = ['fs-watch:/host/task/', 'fs-watch:/host/task//'];
+ const admitted = await admitSharedTaskFsWatchTopics(capture(), ['fs-watch:/host/task', ...aliases]);
+ expect([...admitted.verified]).toEqual(['fs-watch:/host/task']);
+ expect(admitted.topics).toEqual(['fs-watch:/host/task']);
+ // A legacy unnormalized record still admits the exact path the guest received.
+ snapshot.mockResolvedValueOnce({ workingDir: 'C:\\work\\task', remoteHostId: null, permissionMode: 'default', planModeEnabled: false });
+ const legacy = await admitSharedTaskFsWatchTopics(capture(), ['fs-watch:C:\\work\\task', 'fs-watch:C:\\work\\task\\']);
+ expect([...legacy.verified]).toEqual(['fs-watch:C:\\work\\task']);
+ });
+
it('marks an admission stale when the task workdir moves during the lookup', async () => {
const steady = await admitSharedTaskFsWatchTopics(capture(), ['fs-watch:/host/task']);
expect(steady.isFresh()).toBe(true);
diff --git a/apps/desktop/src/main/device-link/sharedTaskFileAccess.ts b/apps/desktop/src/main/device-link/sharedTaskFileAccess.ts
index 1a3aa46201..8898783cce 100644
--- a/apps/desktop/src/main/device-link/sharedTaskFileAccess.ts
+++ b/apps/desktop/src/main/device-link/sharedTaskFileAccess.ts
@@ -6,10 +6,11 @@ import { MAX_SHARED_TASK_TOPICS, sharedTaskWorkdirGeneration, type SharedTaskPee
function deny(): never { throw new Error('[PERMISSION_DENIED] Working directory does not belong to this shared task'); }
/** The task workdir as recorded on this host; guest-supplied paths are only compared to it. */
-async function sharedTaskWorkdir(capture: SharedTaskPeerCapture): Promise<{ workingDir: string; remoteHostId: string | null } | null> {
+async function sharedTaskWorkdir(capture: SharedTaskPeerCapture): Promise<{ workingDir: string; recorded: string; remoteHostId: string | null } | null> {
const snapshot = await getSessionFsSnapshot(capture.author.sessionId);
const workingDir = normalizeWorkingDirForStorage(snapshot?.workingDir);
- return snapshot && workingDir ? { workingDir, remoteHostId: snapshot.remoteHostId } : null;
+ return snapshot?.workingDir && workingDir
+ ? { workingDir, recorded: snapshot.workingDir, remoteHostId: snapshot.remoteHostId } : null;
}
/**
@@ -46,8 +47,13 @@ export async function admitSharedTaskFsWatchTopics(
const own = capture.isCurrent() && capture.authorize('file.read') ? await sharedTaskWorkdir(capture) : null;
const verified = new Set<string>();
if (own && capture.isCurrent()) {
+ // Each topic spelling starts its own host watcher, so admit only the exact
+ // recorded path (and its canonical form) that the guest client receives
+ // from the host. Aliases such as `/task/` or `/task//` would let a guest
+ // accumulate unbounded watchers across frames.
+ const allowed = new Set([own.recorded, own.workingDir]);
for (const topic of watched) {
- if (normalizeWorkingDirForStorage(parseFsWatchTopic(topic)) === own.workingDir) verified.add(topic);
+ if (allowed.has(parseFsWatchTopic(topic)!)) verified.add(topic);
}
}
return { topics: topics.filter((topic) => typeof topic !== 'string' || !watched.has(topic) || verified.has(topic)), verified, isFresh };