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(browser): every action that names a tab refuses a profile of another connection

Dashc8bc9db0b0d9
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
index 031ccf5d5c..4f23dd0d09 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
@@ -716,6 +716,30 @@ describe('UserBrowserBackend · 读取与动作', () => {
expect(evaluations).toBe(2);
});
+ // Review 2026-10-30 (Codex P1): every action that names a tab refuses a profile of another connection.
+ it('act 的 targetId 与 profile 不属于同一连接时拒绝', async () => {
+ const fake = fakeControl({
+ version: '0.4.56',
+ clients: ['client-aaaaaaaa', 'client-bbbbbbbb'],
+ tabs: { 'client-aaaaaaaa': [{ id: 1, url: 'https://a.test/' }], 'client-bbbbbbbb': [] },
+ });
+ const b = backend(fake.control);
+ const listed = (await call(b, { action: 'tabs', profile: 'client-aaaaaaaa' })) as {
+ data?: { tabs?: Array<{ targetId?: string }> };
+ };
+ const targetId = listed.data?.tabs?.[0]?.targetId;
+ const jobsBefore = fake.jobs.length;
+ expect(
+ await call(b, { action: 'act', targetId, profile: 'client-bbbbbbbb', request: { kind: 'click', ref: 'r1' } }),
+ ).toMatchObject({ ok: false, message: expect.stringContaining('不一致') });
+ expect(await call(b, { action: 'snapshot', targetId, profile: 'client-bbbbbbbb' })).toMatchObject({ ok: false });
+ expect(fake.jobs.length).toBe(jobsBefore);
+ // The matching profile (or none) still works.
+ expect(
+ await call(b, { action: 'act', targetId, profile: 'client-aaaa', request: { kind: 'click', ref: 'r1' } }),
+ ).toMatchObject({ ok: true });
+ });
+
// Review 2026-10-30 (Codex P1): a profile that disagrees with the tab's own connection must be refused.
it('navigate 的 targetId 与 profile 属于不同连接时拒绝', async () => {
const fake = fakeControl({
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
index 29ab50d9ff..9d0a453486 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
@@ -552,6 +552,7 @@ export class UserBrowserBackend implements BrowserBackend {
action: BackendRequest['action'],
control: UserBrowserPageControl,
id: string | undefined,
+ profile?: string,
): Promise<{ ok: true; record: TargetRecord } | { ok: false; result: BackendResult }> {
const record = this.resolveTarget(id);
if (!record) {
@@ -566,6 +567,20 @@ export class UserBrowserBackend implements BrowserBackend {
),
};
}
+ // The tab belongs to one connection. A profile that names a different one is a conflict, never a
+ // reason to act in another signed-in browser (or to ignore what the caller asked for).
+ if (profile) {
+ const named = matchProfile(this.connectedClients(control), profile);
+ if (named.length !== 1 || named[0].id !== record.clientId)
+ return {
+ ok: false,
+ result: actionFailed(
+ action,
+ `标签页 ${record.targetId} 属于另一个浏览器连接,和 profile ${profile} 不一致;去掉 profile 或用 tabs 重新选择`,
+ 'BROWSER_RUNTIME_INVALID_REQUEST',
+ ),
+ };
+ }
// 新版扩展按 tabId 寻址并自己核对标签页,不必为每个作业列一遍所有标签页。
if (this.parity(control, record.clientId)) return { ok: true, record };
const listed = await control.bridge.act('tabs', { browser: record.clientId, limit: 100 });
@@ -900,7 +915,7 @@ export class UserBrowserBackend implements BrowserBackend {
private async handleSnapshot(req: BackendRequest): Promise<BackendResult> {
const gate = this.control(req.action);
if (!gate.ok) return gate.result;
- const located = await this.locate(req.action, gate.control, req.targetId);
+ const located = await this.locate(req.action, gate.control, req.targetId, req.profile);
if (!located.ok) return located.result;
if (req.frame) return unsupported(req.action, '按 frame 快照');
const maxChars = Math.min(30000, Math.max(256, req.maxChars ?? 6000));
@@ -973,7 +988,7 @@ export class UserBrowserBackend implements BrowserBackend {
waitedMs: Math.min(30000, Math.max(0, request.timeMs)),
});
}
- const located = await this.locate(req.action, gate.control, targetId);
+ const located = await this.locate(req.action, gate.control, targetId, req.profile);
if (!located.ok) return located.result;
const record = located.record;
const control = gate.control;
@@ -1162,7 +1177,7 @@ export class UserBrowserBackend implements BrowserBackend {
private async handleTabAction(req: BackendRequest): Promise<BackendResult> {
const gate = this.control(req.action);
if (!gate.ok) return gate.result;
- const located = await this.locate(req.action, gate.control, req.targetId);
+ const located = await this.locate(req.action, gate.control, req.targetId, req.profile);
if (!located.ok) return located.result;
const record = located.record;
if (!this.parity(gate.control, record.clientId))
@@ -1261,7 +1276,7 @@ export class UserBrowserBackend implements BrowserBackend {
);
const gate = this.control(req.action);
if (!gate.ok) return gate.result;
- const located = await this.locate(req.action, gate.control, req.targetId);
+ const located = await this.locate(req.action, gate.control, req.targetId, req.profile);
if (!located.ok) return located.result;
const record = located.record;
const control = gate.control;
@@ -1323,7 +1338,7 @@ export class UserBrowserBackend implements BrowserBackend {
private async handleUpload(req: BackendRequest): Promise<BackendResult> {
const gate = this.control(req.action);
if (!gate.ok) return gate.result;
- const located = await this.locate(req.action, gate.control, req.targetId);
+ const located = await this.locate(req.action, gate.control, req.targetId, req.profile);
if (!located.ok) return located.result;
const record = located.record;
if (!this.parity(gate.control, record.clientId)) return outdated(req.action, '上传文件');