Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): enforce market manifest caps
liugaowei576f35457172
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex c97c04c32c..8b6c258c5c 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -28,6 +28,7 @@ import {ghostInstallApprovalToken,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,isGhostInstallApprovalToken,@@ -5680,6 +5681,7 @@ async function installOrUpdateMarketGhostPackageLocked(expected.manifestCap,inspected.canonicalManifest,) ||+ !ghostSettingsUiWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(expected.manifestCap, inspected.canonicalManifest)) {diff --git a/apps/desktop/src/main/plugin-market/install.ts b/apps/desktop/src/main/plugin-market/install.tsindex 0da16f4848..0072e6ae62 100644--- a/apps/desktop/src/main/plugin-market/install.ts+++ b/apps/desktop/src/main/plugin-market/install.ts@@ -17,6 +17,7 @@ import { app } from 'electron';import {ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,unreviewedGhostPermissionItems,@@ -201,6 +202,7 @@ export async function installCustomMarketPlugin(input: {extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostNodeSecretAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||+ !ghostSettingsUiWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(validated.manifest, inspected.canonicalManifest)) {diff --git a/apps/desktop/src/main/plugin-market/service.ts b/apps/desktop/src/main/plugin-market/service.tsindex c0ee726260..d936572d54 100644--- a/apps/desktop/src/main/plugin-market/service.ts+++ b/apps/desktop/src/main/plugin-market/service.ts@@ -15,6 +15,7 @@ import {GHOST_ICON_MAX_BYTES,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,ghostInstallApprovalToken,@@ -1777,6 +1778,7 @@ export class PluginMarketService {extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostNodeSecretAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||+ !ghostSettingsUiWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostSubscribeAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||!ghostUnknownV3FieldsWithinCap(manifestCap, inspected.canonicalManifest)) {diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.tsindex 1fc1cc80f5..d5daf40277 100644--- a/apps/desktop/src/shared/__tests__/ghost.test.ts+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts@@ -15,6 +15,7 @@ import {ghostLocalePathFor,ghostNetworkAuthorizationWithinCap,ghostNodeSecretAuthorizationWithinCap,+ ghostSettingsUiWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,ghostNetworkHostMatches,@@ -4459,6 +4460,85 @@ describe('ghostPermissionProjectionFingerprint', () => {expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, reviewed.manifest)).toBe(true);});+ it('market cap allows OAuth scopes to reorder or narrow but rejects expansion and other drift', () => {+ const manifest = (scopes: string[], label = 'Example account') =>+ validateGhostManifest({+ ...goodChipManifest(),+ slots: ['panel', 'model', 'network'],+ settingsHtml: 'settings.html',+ network: {+ hosts: ['accounts.example.com'],+ secrets: [+ {+ key: 'oauth_token',+ label,+ source: 'oauth',+ inject: { header: 'Authorization', format: 'Bearer {value}' },+ oauth: {+ authorizeUrl: 'https://accounts.example.com/authorize',+ tokenUrl: 'https://accounts.example.com/token',+ scopes,+ },+ },+ ],+ },+ });+ const reviewed = manifest(['read', 'write']);+ const reordered = manifest(['write', 'read']);+ const narrowed = manifest(['read']);+ const expanded = manifest(['read', 'admin']);+ const changedLabel = manifest(['read'], 'Account password');+ expect(+ reviewed.ok && reordered.ok && narrowed.ok && expanded.ok && changedLabel.ok,+ ).toBe(true);+ if (!reviewed.ok || !reordered.ok || !narrowed.ok || !expanded.ok || !changedLabel.ok) {+ return;+ }++ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, reordered.manifest)).toBe(true);+ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, narrowed.manifest)).toBe(true);+ expect(unreviewedGhostPermissionItems(reviewed.manifest, undefined, reordered.manifest)).toEqual(+ [],+ );+ expect(unreviewedGhostPermissionItems(reviewed.manifest, undefined, narrowed.manifest)).toEqual(+ [],+ );+ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, expanded.manifest)).toBe(false);+ expect(+ unreviewedGhostPermissionItems(reviewed.manifest, undefined, changedLabel.manifest),+ ).toEqual([expect.objectContaining({ key: 'network:secret:oauth_token' })]);+ });++ it('market cap requires settings UI presence and only allows its height to stay or shrink', () => {+ const withoutSettings = validateGhostManifest(goodChipManifest());+ const autoHeight = validateGhostManifest({+ ...goodChipManifest(),+ settingsHtml: 'settings.html',+ });+ const fixedHeight = (height: number) =>+ validateGhostManifest({+ ...goodChipManifest(),+ settingsHtml: 'settings.html',+ settingsHeight: height,+ });+ const reviewed = fixedHeight(360);+ const narrowed = fixedHeight(240);+ const expanded = fixedHeight(480);+ expect(+ withoutSettings.ok && autoHeight.ok && reviewed.ok && narrowed.ok && expanded.ok,+ ).toBe(true);+ if (!withoutSettings.ok || !autoHeight.ok || !reviewed.ok || !narrowed.ok || !expanded.ok) {+ return;+ }++ expect(ghostSettingsUiWithinCap(withoutSettings.manifest, autoHeight.manifest)).toBe(false);+ expect(ghostSettingsUiWithinCap(reviewed.manifest, narrowed.manifest)).toBe(true);+ expect(ghostSettingsUiWithinCap(reviewed.manifest, expanded.manifest)).toBe(false);+ expect(ghostSettingsUiWithinCap(reviewed.manifest, autoHeight.manifest)).toBe(false);+ expect(ghostSettingsUiWithinCap(autoHeight.manifest, reviewed.manifest)).toBe(true);+ expect(ghostSettingsUiWithinCap(autoHeight.manifest, withoutSettings.manifest)).toBe(true);+ });+it('same-key/different-labelArgs 同时作废 baseline、diff 与真实包复核', () => {const reviewed = validateGhostManifest({...goodChipManifest(),diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex 5bd9847ac1..deec5c7541 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -2437,6 +2437,38 @@ export function diffInstalledGhostPermissionItems(};}+function ghostOauthAuthorizationWithinCap(+ reviewed: GhostSecretOauthDecl,+ actual: GhostSecretOauthDecl,+): boolean {+ const { scopes: reviewedScopes, ...reviewedBase } = reviewed;+ const { scopes: actualScopes, ...actualBase } = actual;+ return (+ JSON.stringify(actualBase) === JSON.stringify(reviewedBase) &&+ (actualScopes ?? []).every((scope) => (reviewedScopes ?? []).includes(scope))+ );+}++function ghostOauthPermissionWithinCap(+ reviewed: GhostManifest,+ actual: GhostManifest,+ item: GhostPermissionItem,+): boolean {+ const actualSecret = actual.network?.secrets?.find(+ (secret) => `network:secret:${secret.key}` === item.key,+ );+ if (actualSecret?.source !== 'oauth' || !actualSecret.oauth) return false;+ const reviewedSecret = reviewed.network?.secrets?.find(+ (secret) => secret.key === actualSecret.key,+ );+ return (+ reviewedSecret?.source === 'oauth' &&+ reviewedSecret.oauth !== undefined &&+ actualSecret.label === reviewedSecret.label &&+ ghostOauthAuthorizationWithinCap(reviewedSecret.oauth, actualSecret.oauth)+ );+}+/** 返回真实包中超出市场声明与既有安装基线的 Host 能力。 */export function unreviewedGhostPermissionItems(reviewed: GhostManifest,@@ -2462,6 +2494,10 @@ export function unreviewedGhostPermissionItems(ghostNodeSecretAuthorizationWithinCap(reviewed, actual) ||(previouslyInstalled !== undefined &&ghostNodeSecretAuthorizationWithinCap(previouslyInstalled, actual));+ const oauthPermissionApproved = (item: GhostPermissionItem): boolean =>+ ghostOauthPermissionWithinCap(reviewed, actual, item) ||+ (previouslyInstalled !== undefined &&+ ghostOauthPermissionWithinCap(previouslyInstalled, actual, item));return ghostPermissionItems(actual).filter((item) =>!approved.has(ghostPermissionProjectionKey(item)) &&@@ -2473,7 +2509,10 @@ export function unreviewedGhostPermissionItems(!(item.key === 'preview' && previewApproved) &&// Node secret 的展示 key 带完整 methods;换序或收窄是收权。URL/hint 与// entry 等 Host 实际消费字段由专用上限比较守住,不能依赖展示投影相等。- !(item.key.startsWith('node:secret:') && nodeSecretsApproved),+ !(item.key.startsWith('node:secret:') && nodeSecretsApproved) &&+ // OAuth 展示 detail 带完整 scopes;换序或收窄同样是收权。其余 OAuth+ // 参数、凭证标签与注入语义仍由专用上限和完整投影逐项钉住。+ !oauthPermissionApproved(item),);}@@ -2507,6 +2546,18 @@ export function ghostNodeSecretAuthorizationWithinCap(return true;}+/** 市场清单对真实包设置 WebView 暴露面的授权上限。 */+export function ghostSettingsUiWithinCap(+ reviewed: GhostManifest,+ actual: GhostManifest,+): boolean {+ if (actual.settingsHtml === undefined) return true;+ if (reviewed.settingsHtml === undefined) return false;+ if (actual.settingsHeight === undefined) return reviewed.settingsHeight === undefined;+ if (reviewed.settingsHeight === undefined) return true;+ return actual.settingsHeight <= reviewed.settingsHeight;+}+/*** 市场清单对真实包的 network 授权语义上限。*@@ -2548,8 +2599,8 @@ export function ghostNetworkAuthorizationWithinCap() {return false;}- if (secret.oauth !== undefined && JSON.stringify(secret.oauth) !== JSON.stringify(cap.oauth)) {- return false;+ if (secret.oauth !== undefined) {+ if (!cap.oauth || !ghostOauthAuthorizationWithinCap(cap.oauth, secret.oauth)) return false;}}diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.mdindex 46a6b125a5..4b5a206423 100644--- a/docs/dev-rules/plugin-security-and-authoring.md+++ b/docs/dev-rules/plugin-security-and-authoring.md@@ -130,7 +130,9 @@解除。忙碌跳过不记失败,用户手动重试不受退避限制。- 服务端包必须通过 release SHA/大小校验,真实包能力不得超出该 release 的市场 manifest;自定义市场以发现并规范化的 manifest 为能力上限。能力上限内的新版声明可静默更新,超出- 则按包内容不一致拒绝并留待来源修复,不转成用户审批流程。+ 则按包内容不一致拒绝并留待来源修复,不转成用户审批流程。能力上限按 Host 实际消费语义+ 比较:真实包不得从无到有增加 `settingsHtml` 设置 WebView 或扩大固定 `settingsHeight`;+ OAuth `scopes` 换序或取子集属于收权,其它 OAuth、凭证标签与注入字段仍须保持在清单上限内。- 本地 `.cindy` 没有稳定来源,不自动更新;用户再次导入同 id 新包时直接原位更新,由 Main保持当前启用状态。- Host receipt 是安装事务和运行完整性的状态记录,不是一次交互式“能力授权”。合法的安装/更新