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(plugin): retain legacy OIDC authorization

liugaowei57465245dead
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
index ac5741103d..c0257a4b38 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/connectionAudienceResolver.test.ts
@@ -155,6 +155,38 @@ describe('installed Plugin Connection audience resolver', () => {
).toBeNull();
});
+ it('keeps legacy Forge OIDC for an approved current-organization prefix plugin', () => {
+ const forgeManifest: GhostManifest = { ...manifest, id: 'acme-tool' };
+ const resolver = loadConnectionAudienceResolver({
+ ...resolverOptions(forgeManifest, null),
+ readInstallOrigin: () => 'agent-forge',
+ readApprovedPackageSha256: () => 'a'.repeat(64),
+ lookupOrganizationPrefix: () => ({ kind: 'known', pluginPrefix: 'acme' }),
+ });
+ expect(resolver.resolve('acme-tool', identity)).toEqual({
+ membershipId: 'membership-1',
+ audience: 'org-example:acme-tool',
+ pluginSlug: 'acme-tool',
+ allowedHosts: ['service-a.x.test'],
+ });
+ });
+
+ it('does not extend legacy Forge OIDC to a manual install or another prefix', () => {
+ const forgeManifest: GhostManifest = { ...manifest, id: 'acme-tool' };
+ for (const options of [
+ { readInstallOrigin: () => 'manual' as const, pluginPrefix: 'acme' },
+ { readInstallOrigin: () => 'agent-forge' as const, pluginPrefix: 'other' },
+ ]) {
+ const resolver = loadConnectionAudienceResolver({
+ ...resolverOptions(forgeManifest, null),
+ readInstallOrigin: options.readInstallOrigin,
+ readApprovedPackageSha256: () => 'a'.repeat(64),
+ lookupOrganizationPrefix: () => ({ kind: 'known', pluginPrefix: options.pluginPrefix }),
+ });
+ expect(resolver.resolve('acme-tool', identity)).toBeNull();
+ }
+ });
+
it('requires the managed secret target to match a declared exact host', () => {
const resolver = loadConnectionAudienceResolver({
...resolverOptions(),
diff --git a/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts b/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts
index 993879af46..936d477292 100644
--- a/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts
+++ b/apps/desktop/src/main/cindy-brain/connectionAudienceResolver.ts
@@ -1,12 +1,14 @@
/**
- * Host-owned Connection audience resolution. Only organization-scoped Plugin
- * Market installs with an intact manifest may receive a token; the Host derives
- * the audience from the current organization and the installed plugin id.
+ * Host-owned Connection audience resolution. New grants require an intact
+ * organization-scoped Plugin Market install; a bounded read-only fallback keeps
+ * legacy Forge receipts working. The Host derives the audience from the current
+ * organization and the installed plugin id.
*/
import { isValidGhostId, isValidGhostNetworkHostPattern } from '../../shared/ghost.js';
import type { GhostManifest } from '../../shared/ghost.js';
import type { PluginMarketInstallationRecord } from '../plugin-market/ledger.js';
import { PLUGIN_MEMBER_PUBLISHER_GHOST_ID } from '../plugin-publisher/types.js';
+import { PLUGIN_PREFIX_PATTERN } from '@cindy/plugin-protocol';
export interface ConnectionAudienceIdentity {
membershipId: string;
@@ -58,6 +60,11 @@ export interface LoadConnectionAudienceResolverOptions {
readInstalledManifest(ghostId: string): GhostManifest | null;
readInstalledManifestDigest(ghostId: string): string | null;
readMarketInstallation(ghostId: string): PluginMarketInstallationRecord | null;
+ readApprovedPackageSha256?(ghostId: string): string | null;
+ readInstallOrigin?(ghostId: string): 'manual' | 'agent-forge';
+ lookupOrganizationPrefix?(
+ orgId: string,
+ ): { kind: 'known'; pluginPrefix: string | null } | { kind: 'absent' } | { kind: 'unavailable' };
log?: {
info: (msg: string, meta?: Record<string, unknown>) => void;
warn: (msg: string, meta?: Record<string, unknown>) => void;
@@ -113,6 +120,34 @@ export function loadConnectionAudienceResolver(
};
};
+ const readManifest = (): GhostManifest | null => {
+ try {
+ return options.readInstalledManifest(ghostId);
+ } catch {
+ return null;
+ }
+ };
+
+ // 只读兼容升级前的 Forge receipt。新安装不再写 agent-forge;但旧插件的
+ // Connection JWT 资格不能因客户端升级中断。个人身份、缺失组织 slug、未知
+ // 前缀与缺失批准包哈希都已在进入此分支前后 fail closed。
+ const forgeOrigin = options.readInstallOrigin?.(ghostId);
+ if (forgeOrigin === 'agent-forge') {
+ const prefixLookup = options.lookupOrganizationPrefix?.(identity.orgId);
+ const prefix =
+ prefixLookup && prefixLookup.kind === 'known' ? prefixLookup.pluginPrefix : null;
+ if (prefix && PLUGIN_PREFIX_PATTERN.test(prefix) && ghostId.startsWith(`${prefix}-`)) {
+ const approvedSha = options.readApprovedPackageSha256?.(ghostId) ?? null;
+ if (!approvedSha || !/^[a-f0-9]{64}$/.test(approvedSha)) {
+ return reject('forge-package-sha-missing');
+ }
+ const manifest = readManifest();
+ if (!manifest) return reject('plugin-not-installed');
+ if (manifest.id !== ghostId) return reject('plugin-id-mismatch');
+ return finish(manifest);
+ }
+ }
+
let installation: PluginMarketInstallationRecord | null = null;
try {
installation = options.readMarketInstallation(ghostId);
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 4184a8c305..e5b10567f8 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -27,6 +27,7 @@ import {
GHOST_NOTIFY_MIN_INTERVAL_MS,
ghostInstallApprovalToken,
ghostNetworkAuthorizationWithinCap,
+ ghostSubscribeAuthorizationWithinCap,
isGhostInstallApprovalToken,
ghostAppContextLocale,
unreviewedGhostPermissionItems,
@@ -2546,7 +2547,7 @@ function readInstalledGhostManifestDigest(ghostId: string): string | null {
return parsed.ok ? ghostManifestDigest(parsed.manifest) : null;
}
-/** Resolve Connection metadata only from a trusted organization market install. */
+/** Resolve Connection metadata from trusted organization installs or legacy Forge receipts. */
function getConnectionAudienceResolver(): ConnectionAudienceResolver {
if (!connectionAudienceResolverSingleton) {
connectionAudienceResolverSingleton = loadConnectionAudienceResolver({
@@ -2556,6 +2557,13 @@ function getConnectionAudienceResolver(): ConnectionAudienceResolver {
.find((candidate) => candidate.manifest.id === ghostId)?.manifest ?? null,
readInstalledManifestDigest: readInstalledGhostManifestDigest,
readMarketInstallation: (ghostId) => getPluginMarketLedger().installationForGhost(ghostId),
+ readApprovedPackageSha256: (ghostId) =>
+ getGhostManager().approvedInstallEvidence(ghostId)?.packageSha256 ?? null,
+ readInstallOrigin: (ghostId) => getGhostManager().readEffectiveInstallOrigin(ghostId),
+ lookupOrganizationPrefix: (orgId) =>
+ createOrganizationPrefixStore(
+ ownerScopedUserDataPath('plugin-market', 'organization.v1.json'),
+ ).lookup(orgId),
log,
});
}
@@ -5646,7 +5654,8 @@ async function installOrUpdateMarketGhostPackageLocked(
);
if (
undeclaredCapabilities.length > 0 ||
- !ghostNetworkAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest)
+ !ghostNetworkAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest) ||
+ !ghostSubscribeAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest)
) {
log.warn('market package exceeds catalog manifest capabilities', {
ghostId: expected.ghostId,
diff --git a/apps/desktop/src/main/plugin-market/install.ts b/apps/desktop/src/main/plugin-market/install.ts
index b575b87680..d67d6f0786 100644
--- a/apps/desktop/src/main/plugin-market/install.ts
+++ b/apps/desktop/src/main/plugin-market/install.ts
@@ -16,6 +16,7 @@ import { app } from 'electron';
import {
ghostNetworkAuthorizationWithinCap,
+ ghostSubscribeAuthorizationWithinCap,
unreviewedGhostPermissionItems,
validateGhostManifest,
type GhostManifest,
@@ -196,7 +197,8 @@ export async function installCustomMarketPlugin(input: {
);
if (
extraCapabilities.length > 0 ||
- !ghostNetworkAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest)
+ !ghostNetworkAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||
+ !ghostSubscribeAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest)
) {
throwIpcError(
'GHOST_FILE_INVALID',
diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.ts
index 0d6b1a16ed..1b9682f7fc 100644
--- a/apps/desktop/src/main/plugin-market/service.ts
+++ b/apps/desktop/src/main/plugin-market/service.ts
@@ -14,6 +14,7 @@ import { app, dialog } from 'electron';
import {
GHOST_ICON_MAX_BYTES,
ghostNetworkAuthorizationWithinCap,
+ ghostSubscribeAuthorizationWithinCap,
ghostInstallApprovalToken,
ghostIconMimeType,
isSafeGhostRelativePath,
@@ -1750,7 +1751,8 @@ export class PluginMarketService {
);
if (
extraCapabilities.length > 0 ||
- !ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest)
+ !ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||
+ !ghostSubscribeAuthorizationWithinCap(manifestCap, inspected.canonicalManifest)
) {
throwIpcError(
'GHOST_FILE_INVALID',
diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.ts
index 6ea58a5a9a..0d06a84c68 100644
--- a/apps/desktop/src/shared/__tests__/ghost.test.ts
+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts
@@ -14,6 +14,7 @@ import {
ghostExternalLinkUrls,
ghostLocalePathFor,
ghostNetworkAuthorizationWithinCap,
+ ghostSubscribeAuthorizationWithinCap,
ghostNetworkHostMatches,
ghostPanelKind,
ghostPermissionBaselineKey,
@@ -2306,6 +2307,21 @@ describe('ghost · subscribe 订阅详单校验(卡槽①,2026-07-12)', () => {
}
});
+ it('市场能力上限按具体订阅 topic 比较,不把 turn 与 session 当成同一授权', () => {
+ const turnOnly = validateGhostManifest(withSub({ topics: ['turn'] }));
+ const sessionOnly = validateGhostManifest(withSub({ topics: ['session'] }));
+ expect(turnOnly.ok && sessionOnly.ok).toBe(true);
+ if (!turnOnly.ok || !sessionOnly.ok) return;
+
+ expect(
+ unreviewedGhostPermissionItems(turnOnly.manifest, undefined, sessionOnly.manifest),
+ ).toEqual([]);
+ expect(
+ ghostSubscribeAuthorizationWithinCap(turnOnly.manifest, sessionOnly.manifest),
+ ).toBe(false);
+ expect(ghostSubscribeAuthorizationWithinCap(turnOnly.manifest, turnOnly.manifest)).toBe(true);
+ });
+
it('will-assistant-message:出口钩子合法(继承 resident 要求),单列一档权限行', () => {
const noResident = validateGhostManifest(withSub({ hooks: ['will-assistant-message'] }));
expect(noResident.ok).toBe(false); // resident 要求 key 在 hooks 非空,自动覆盖新钩子
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index ca609edbd6..616946850d 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -861,8 +861,9 @@ export const GHOST_OAUTH_BOUNCE_PATH_RE = /^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)
* `gh auth token`,不可用时回落到同 key 经 /secrets 保存的 PAT。两种值都
* 只在 networkSlot 请求 GitHub API 时注入,不进入插件、Renderer、KV 或日志。
* - 'oidc-token':值 = Cindy 为当前企业 Membership 签发的短时 Connection
- * JWT。只有当前组织的 Plugin Market organization 安装记录和 manifest digest
- * 校验通过时,Host 才根据当前组织和插件 id 推导 audience;插件不能声明或读取。
+ * JWT。新授权只有当前组织的 Plugin Market organization 安装记录和 manifest
+ * digest 校验通过时才会签发;升级前已有的 agent-forge receipt 保留只读兼容。
+ * Host 根据当前组织和插件 id 推导 audience,插件不能声明或读取。
* 令牌只在 networkSlot 发请求时注入,且永不进入 Node Worker。
*
* ('login-feishu-token' 已于 2026-07-17 随飞书登录整体下线退役——xd-feishu
@@ -2522,6 +2523,25 @@ export function ghostNetworkAuthorizationWithinCap(
return true;
}
+/** 市场清单对真实包的订阅事件授权上限;具体 topic/hook 只能保持或收缩。 */
+export function ghostSubscribeAuthorizationWithinCap(
+ reviewed: GhostManifest,
+ actual: GhostManifest,
+): boolean {
+ const actualSubscribe = actual.subscribe;
+ if (!actualSubscribe) return true;
+ const reviewedSubscribe = reviewed.subscribe;
+ if (!reviewedSubscribe) return false;
+ return (
+ (actualSubscribe.topics ?? []).every((topic) =>
+ (reviewedSubscribe.topics ?? []).includes(topic),
+ ) &&
+ (actualSubscribe.hooks ?? []).every((hook) =>
+ (reviewedSubscribe.hooks ?? []).includes(hook),
+ )
+ );
+}
+
/**
* icon 允许的图片扩展名 → mime(校验与 main 读盘供图共用同一口径)。
* 不收 svg:svg 可携带脚本,虽经 <img> 渲染不执行,仍不给这个面。