From e05fcf628570f30a9410418f7f0d8782532ca29d Mon Sep 17 00:00:00 2001 From: QQ Date: Tue, 17 Nov 2026 08:50:32 +0800 Subject: [PATCH] Import packages/plugin/tests/harness-remote-bridge.test.ts --- .../tests/harness-remote-bridge.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/plugin/tests/harness-remote-bridge.test.ts b/packages/plugin/tests/harness-remote-bridge.test.ts index 9e006ec..e3716b6 100644 --- a/packages/plugin/tests/harness-remote-bridge.test.ts +++ b/packages/plugin/tests/harness-remote-bridge.test.ts @@ -1686,6 +1686,43 @@ describe('HarnessRemoteBridge', () => { }) }) +it('accepts absolute file paths through the trusted cwd alias without accepting other symlinks', async () => { + const fixture = await mkdtemp(join(tmpdir(), 'remote-cwd-alias-')) + let bridge: HarnessRemoteBridge | undefined + try { + const workspace = join(fixture, 'workspace') + await mkdir(workspace) + const root = await realpath(workspace) + const cwd = join(fixture, 'trusted-cwd') + const otherAlias = join(fixture, 'untrusted-alias') + await symlink(root, cwd, process.platform === 'win32' ? 'junction' : 'dir') + await symlink(root, otherAlias, process.platform === 'win32' ? 'junction' : 'dir') + await writeFile(join(root, 'inside.txt'), 'inside') + await writeFile(join(fixture, 'outside.txt'), 'outside') + await symlink(join(root, 'inside.txt'), join(root, 'internal-link.txt'), 'file') + const dispatch = vi.fn(async () => ({ ok: true as const, value: {} })) + bridge = new HarnessRemoteBridge(gateway({ dispatch }), vi.fn(async () => undefined), + undefined, undefined, undefined, undefined, async () => cwd) + for (const endpoint of ['workspaceFiles/read', 'workspaceFiles/readBytes', 'workspaceFiles/readAll']) { + for (const path of [join(cwd, 'inside.txt'), join(root, 'inside.txt')]) { + await expect(bridge.call({ endpoint, payload: { args: { workspaceFileScopeId: 'session-1', path } } })) + .resolves.toMatchObject({ ok: true }) + expect(dispatch).toHaveBeenLastCalledWith(endpoint, + expect.objectContaining({ args: expect.objectContaining({ path: 'inside.txt' }) }), expect.any(AbortSignal)) + } + for (const path of [join(fixture, 'outside.txt'), join(otherAlias, 'inside.txt'), join(cwd, 'internal-link.txt')]) { + dispatch.mockClear() + await expect(bridge.call({ endpoint, payload: { args: { workspaceFileScopeId: 'session-1', path } } })) + .rejects.toMatchObject({ code: 'WORKSPACE_PATH_DENIED' }) + expect(dispatch).not.toHaveBeenCalled() + } + } + } finally { + await bridge?.closeAll() + await rm(fixture, { recursive: true, force: true }) + } +}) + function stubTerminalSpawner(): RemoteTerminalSpawner { return async (): Promise => ({ output: (async function* () { return })(),