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-extension): verify the official source; pin pairings to the shown extension ids

Dashc2be1a5e302f
diff --git a/apps/desktop/src/main/browser-extension/__tests__/bridge.test.ts b/apps/desktop/src/main/browser-extension/__tests__/bridge.test.ts
index b3fa7b44e2..2c7f3234b6 100644
--- a/apps/desktop/src/main/browser-extension/__tests__/bridge.test.ts
+++ b/apps/desktop/src/main/browser-extension/__tests__/bridge.test.ts
@@ -314,6 +314,19 @@ describe('bridge · 连接与身份', () => {
expect((await c.request('/act', { action: 'click' })).status).toBe(404);
});
+ // Review 2026-10-30 (Codex P1): a plugin could pair any extension id it pushed.
+ it('插件推送的配对只接受清单里钉死的扩展 id', async () => {
+ const { bridge } = await fixture();
+ bridge.setTrustedClients([
+ { id: 'c1', origin: 'chrome-extension://' + EXT_ID, extensionId: EXT_ID, publicKey: 'k' },
+ { id: 'c2', origin: 'chrome-extension://' + 'z'.repeat(32), extensionId: 'z'.repeat(32), publicKey: 'k' },
+ ]);
+ const status = await bridge.status();
+ expect(status.extension_ids).toEqual([EXT_ID, STORE_ID]);
+ // Only the listed extension is kept as a pin: the unknown one never becomes trusted.
+ expect((bridge as unknown as { pins: Array<{ extensionId: string }> }).pins.map((p) => p.extensionId)).toEqual([EXT_ID]);
+ });
+
it('官方扩展经 native 绑定后无需手工配对即可认证;伪造调用方不能自称官方', async () => {
const { bridge, client } = await fixture();
for (const extensionId of [EXT_ID, STORE_ID]) {
diff --git a/apps/desktop/src/main/browser-extension/bridge.ts b/apps/desktop/src/main/browser-extension/bridge.ts
index 916f51f1df..fcf873910c 100644
--- a/apps/desktop/src/main/browser-extension/bridge.ts
+++ b/apps/desktop/src/main/browser-extension/bridge.ts
@@ -1024,7 +1024,11 @@ export class BrowserExtensionBridge {
typeof c === 'object' &&
typeof (c as BrowserExtensionTrustedClient).id === 'string' &&
typeof (c as BrowserExtensionTrustedClient).origin === 'string' &&
- typeof (c as BrowserExtensionTrustedClient).extensionId === 'string',
+ typeof (c as BrowserExtensionTrustedClient).extensionId === 'string' &&
+ // A Chromium extension must be one the user was shown at install, whatever the plugin pushes.
+ // (Safari extensions are paired explicitly by the user and carry their own identifiers.)
+ (!(c as BrowserExtensionTrustedClient).origin.startsWith('chrome-extension://') ||
+ this.knownIds.has((c as BrowserExtensionTrustedClient).extensionId)),
);
for (const c of this.clients.values()) c.trusted = this.approved(c);
return { ok: true };
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
index 82bb322c45..02b9721fb7 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/browserExtensionSlot.test.ts
@@ -151,6 +151,7 @@ async function makeSlot(
return true;
}),
policyDir: () => dir,
+ isVerifiedOfficial: () => true,
ownerScopeKey: () => 'owner-a',
createBridge: (options) => {
const bridge = new FakeBridge(options);
@@ -368,6 +369,33 @@ describe('browserExtensionSlot · 管子上行', () => {
expect(again.sent.some(([, payload]) => (payload as { name?: string }).name === 'browser-extension-policy-request')).toBe(false);
});
+ // Review 2026-10-30 (Codex P1): a manifest that merely claims the official id must not get the native
+ // host, My browser or saved pairings.
+ it('未核验来源的包不装 native host、不接管「我的浏览器」、不继承配对', async () => {
+ const clients = [{ id: 'c1', origin: 'chrome-extension://' + CHROME_ID, extensionId: CHROME_ID, publicKey: 'k' }];
+ const { slot, bridges, natives, dir } = await makeSlot({ isVerifiedOfficial: () => false });
+ await fs.writeFile(
+ path.join(dir, encodeURIComponent('_root__my-browser') + '.json'),
+ JSON.stringify({ version: 1, source: '[null,null]', trustedClients: clients }),
+ );
+ slot.reconcile([extGhost()]);
+ await vi.waitFor(() => expect(bridges[0]?.started).toBe(true));
+ expect(natives).toHaveLength(0);
+ expect(slot.getPageControl()).toBeNull();
+ expect(bridges[0].calls.some(([name]) => name === 'setTrustedClients')).toBe(false);
+ });
+
+ // A pairing cache written before sources were recorded is stamped when first read.
+ it('没有来源记录的旧配对缓存读到后立即补上来源', async () => {
+ const clients = [{ id: 'c1', origin: 'chrome-extension://' + CHROME_ID, extensionId: CHROME_ID, publicKey: 'k' }];
+ const { slot, bridges, dir } = await makeSlot();
+ const file = path.join(dir, encodeURIComponent('_root__my-browser') + '.json');
+ await fs.writeFile(file, JSON.stringify({ version: 1, trustedClients: clients }));
+ slot.reconcile([extGhost()]);
+ await vi.waitFor(() => expect(bridges[0]?.started).toBe(true));
+ await vi.waitFor(async () => expect(JSON.parse(await fs.readFile(file, 'utf8')).source).toBe('[null,null]'));
+ });
+
// Review 2026-10-29 (Codex P1): a package from another source reused the old package's pairings.
it('换成其它来源的包时不沿用旧配对', async () => {
const { slot, bridges, sent, dir } = await makeSlot();
diff --git a/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts b/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
index 28fd22485c..cfe36f1b11 100644
--- a/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
+++ b/apps/desktop/src/main/cindy-brain/browserExtensionSlot.ts
@@ -60,9 +60,10 @@ const OFFICIAL_NATIVE_HOSTS: ReadonlyMap<string, string> = new Map([
['my-browser', 'com.makecindy.browser'],
]);
-export function mayInstallNativeHost(ghost: InstalledGhost): boolean {
+export function mayInstallNativeHost(ghost: InstalledGhost, verified = true): boolean {
const name = ghost.manifest.browserExtension?.nativeHost?.name;
return (
+ verified &&
name !== undefined &&
ghost.namespace == null &&
OFFICIAL_NATIVE_HOSTS.get(ghost.manifest.id) === name &&
@@ -71,8 +72,9 @@ export function mayInstallNativeHost(ghost: InstalledGhost): boolean {
}
/** 「我的浏览器」只由官方 Cindy Chrome 提供;其它插件声明 pageControl 一律忽略(2026-10-30 决定)。 */
-export function mayProvidePageControl(ghost: InstalledGhost): boolean {
+export function mayProvidePageControl(ghost: InstalledGhost, verified = true): boolean {
return (
+ verified &&
ghost.manifest.browserExtension?.pageControl === true &&
ghost.namespace == null &&
OFFICIAL_NATIVE_HOSTS.has(ghost.manifest.id)
@@ -80,6 +82,12 @@ export function mayProvidePageControl(ghost: InstalledGhost): boolean {
}
export interface BrowserExtensionSlotDeps {
+ /**
+ * Whether this installed package really is the official one (installed from the public market with
+ * the approved bytes; unpacked dev builds count). The manifest id alone proves nothing: only a
+ * verified package may install the native host, provide My browser or inherit saved pairings.
+ */
+ isVerifiedOfficial(ghost: InstalledGhost): boolean;
getGhost(id: string): InstalledGhost | null;
/** 把转交事件投到插件逻辑页;false = 逻辑页不在线。 */
sendToGhost(ghostId: string, payload: unknown): boolean;
@@ -122,6 +130,8 @@ interface Entry {
interface SavedBrowserExtensionState {
trustedClients: unknown[];
+ /** Read from a file written before pairings recorded their package source. */
+ unstamped?: true;
}
function fail(
@@ -177,12 +187,13 @@ export class GhostBrowserExtensionSlot {
private start(instanceId: string, ghost: InstalledGhost, ownerScopeKey: string): void {
const needs = ghost.manifest.browserExtension!;
const cacheDir = this.deps.policyDir();
- if (needs.nativeHost && !mayInstallNativeHost(ghost))
- this.deps.log?.warn('browser extension native host ignored: only the official plugin may install one', {
+ const verified = this.deps.isVerifiedOfficial(ghost);
+ if (needs.nativeHost && !mayInstallNativeHost(ghost, verified))
+ this.deps.log?.warn('browser extension native host ignored: only the verified official plugin may install one', {
instanceId,
hostName: needs.nativeHost.name,
});
- const native = needs.nativeHost && mayInstallNativeHost(ghost)
+ const native = needs.nativeHost && mayInstallNativeHost(ghost, verified)
? (this.deps.createNativeBinding ?? createNativeBinding)({
hostName: needs.nativeHost.name,
binaryDir: path.join(ghost.dir, needs.nativeHost.binary),
@@ -214,7 +225,10 @@ export class GhostBrowserExtensionSlot {
entry.ready = (async () => {
// The old bridge must release its port and native registration before this one claims them.
await previous?.catch(() => undefined);
- const saved = await this.readSaved(cacheDir, instanceId, entry.source);
+ // Pairings are restored only for the verified official package, and a file saved before pairings
+ // carried a source is stamped now so a later replacement cannot inherit it.
+ const saved = verified ? await this.readSaved(cacheDir, instanceId, entry.source) : null;
+ if (saved?.unstamped) void this.persist(entry, { trustedClients: saved.trustedClients });
if (saved) {
entry.saved = saved;
try {
@@ -408,7 +422,7 @@ export class GhostBrowserExtensionSlot {
getPageControl(): UserBrowserPageControl | null {
for (const [instanceId, entry] of this.entries) {
- if (mayProvidePageControl(entry.ghost)) {
+ if (mayProvidePageControl(entry.ghost, this.deps.isVerifiedOfficial(entry.ghost))) {
return {
bridge: entry.bridge,
ghostId: entry.ghost.manifest.id,
@@ -450,6 +464,7 @@ export class GhostBrowserExtensionSlot {
}
return {
trustedClients: Array.isArray(raw.trustedClients) ? raw.trustedClients : [],
+ ...(raw.source === undefined ? { unstamped: true as const } : {}),
};
} catch {
return null;
diff --git a/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts b/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
index f7f7d434e5..c493e24c98 100644
--- a/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
@@ -212,6 +212,20 @@ export function matchesPendingLegacyForge(
* Pure first-party privilege conclusion from already-collected facts.
* Does not read disk, ledger, or Electron.
*/
+/**
+ * Installed from the public market with the bytes the user approved (root namespace, not a Forge
+ * self-test). Unlike isTrustedPublicCindyResource it does not require the reserved `cindy-` prefix:
+ * the official Cindy Chrome plugin predates it. This is source evidence, not a privilege grant.
+ */
+export function isTrustedPublicMarketPackage(facts: GhostFirstPartyFacts): boolean {
+ const record = facts.marketRecord;
+ return facts.namespace === null && facts.installOrigin === 'manual' &&
+ record !== null && record.installed && record.source === 'market' &&
+ record.scope === 'public' && record.organizationId === null &&
+ record.approvedPackageSha256 !== null && PACKAGE_SHA256_RE.test(record.sha256) &&
+ record.sha256 === record.approvedPackageSha256;
+}
+
export function resolveGhostFirstPartyPrivilege(facts: GhostFirstPartyFacts): GhostFirstPartyPrivilege {
if (facts.builtin && facts.trustedSource?.kind === 'builtin-official' &&
hasTrustedFirstPartySource(facts)) {
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index e0238635b7..852cd2efa6 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -476,6 +476,7 @@ import {
authorizeGhostTokenBroker,
captureLegacyFirstPartyEligibility,
isTrustedMivoSecretAlias,
+ isTrustedPublicMarketPackage,
} from './ghostFirstPartyPrivilege.js';
import { isTrustedXdGhostForScriptTarget } from './ghostTrustedXdTarget.js';
import { classifyGhostLocalUpdateSource, type GhostLocalUpdateSourceDecision } from './ghostLocalUpdateSource.js';
@@ -4050,6 +4051,13 @@ export function getGhostBrowserExtensionSlot(): GhostBrowserExtensionSlot {
if (!ghost) return false;
return (await getGhostRuntime().spawn(ghost)).ok;
},
+ // Unpacked builds are developer builds and count as official, like the reserved-id rule; a packaged
+ // build needs public-market source evidence (the manifest id alone is self-reported).
+ isVerifiedOfficial: (ghost) => {
+ if (!app.isPackaged) return true;
+ const load = loadGhostFirstPartyFactsForGhost(installedGhostStoragePart(ghost), 'runtime');
+ return load.kind === 'ready' && isTrustedPublicMarketPackage(load.facts);
+ },
policyDir: () => ownerScopedUserDataPath('browser-extension'),
ownerScopeKey: () => activeOwnerScopeKey(),
log,
diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.md
index dd7deb9c08..095e6ff67e 100644
--- a/docs/dev-rules/plugin-security-and-authoring.md
+++ b/docs/dev-rules/plugin-security-and-authoring.md
@@ -133,7 +133,8 @@ Library 请求同时绑定迁移代次和安装批准,根解析、排队及开
`extensionIds` 是允许连接的扩展 id(装入时逐条展示并钉死),可选 `nativeHost{name,binary}`
由宿主复制包内平台二进制并注册 Native Messaging:该程序在插件沙箱外运行且同一账号的所有
Cindy 共用一份注册,宿主只为官方 Cindy Chrome(`my-browser`、`com.makecindy.browser`、
- 声明了 Node 程序)安装,其它插件的声明被忽略(2026-10-29 决定,宿主代码点名具体插件的唯一
+ 声明了 Node 程序,且打包版里来自公共市场并与批准字节一致——清单 id 是自报的,不算身份;
+ 未打包的开发版视为官方)安装,其它插件的声明被忽略(2026-10-29 决定,宿主代码点名具体插件的唯一
例外);注册在没有任何运行中的 Cindy 仍在使用时撤销。可选 `pageControl: true` 表示扩展实现
页面控制契约、可作为 Browser Use 的「我的浏览器」执行端;同样只有官方 Cindy Chrome 的声明生效,其它
插件声明了也不会接管「我的浏览器」(2026-10-30 决定)。宿主代码里不得出现具体插件名