Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): bound node secret delivery
liugaowei9e519fb70b2d
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex c9528c6f5c..a7590007b1 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,+ ghostNodeSecretAuthorizationWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,isGhostInstallApprovalToken,@@ -5665,6 +5666,10 @@ async function installOrUpdateMarketGhostPackageLocked(if (undeclaredCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(expected.manifestCap, inspected.canonicalManifest) ||+ !ghostNodeSecretAuthorizationWithinCap(+ 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 51f71e84bd..0da16f4848 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,+ ghostNodeSecretAuthorizationWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,unreviewedGhostPermissionItems,@@ -199,6 +200,7 @@ export async function installCustomMarketPlugin(input: {if (extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(validated.manifest, inspected.canonicalManifest) ||+ !ghostNodeSecretAuthorizationWithinCap(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 e98509776e..c0ee726260 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,+ ghostNodeSecretAuthorizationWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,ghostInstallApprovalToken,@@ -1775,6 +1776,7 @@ export class PluginMarketService {if (extraCapabilities.length > 0 ||!ghostNetworkAuthorizationWithinCap(manifestCap, inspected.canonicalManifest) ||+ !ghostNodeSecretAuthorizationWithinCap(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 14da60f25c..ed3cc8adb8 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,+ ghostNodeSecretAuthorizationWithinCap,ghostSubscribeAuthorizationWithinCap,ghostUnknownV3FieldsWithinCap,ghostNetworkHostMatches,@@ -4582,6 +4583,53 @@ describe('ghostPermissionProjectionFingerprint', () => {expect(ghostUnknownV3FieldsWithinCap(reviewed.manifest, undeclared.manifest)).toBe(false);});+ it('Node 凭证方法可换序或收窄,但 Host 消费字段不能超出市场声明', () => {+ const manifest = (binding: Record<string, unknown>) =>+ validateGhostManifest({+ schemaVersion: 3,+ minCindyVersion: '0.1.61',+ id: 'node-secret-helper',+ name: 'Node secret helper',+ version: '1.0.0',+ entry: 'main.js',+ settingsHtml: 'settings.html',+ node: {+ entry: 'worker.js',+ protocol: 'json-rpc-stdio',+ secretBindings: [+ {+ key: 'api_key',+ label: 'API key',+ methods: ['read', 'write'],+ hint: 'Create a key',+ url: 'https://example.com/keys',+ ...binding,+ },+ ],+ },+ });+ const reviewed = manifest({});+ const reordered = manifest({ methods: ['write', 'read'] });+ const narrowed = manifest({ methods: ['read'] });+ const expanded = manifest({ methods: ['read', 'write', 'delete'] });+ const changedUrl = manifest({ url: 'https://evil.example/keys' });+ expect(+ reviewed.ok && reordered.ok && narrowed.ok && expanded.ok && changedUrl.ok,+ ).toBe(true);+ if (!reviewed.ok || !reordered.ok || !narrowed.ok || !expanded.ok || !changedUrl.ok) return;++ expect(ghostNodeSecretAuthorizationWithinCap(reviewed.manifest, reordered.manifest)).toBe(true);+ expect(ghostNodeSecretAuthorizationWithinCap(reviewed.manifest, narrowed.manifest)).toBe(true);+ expect(unreviewedGhostPermissionItems(reviewed.manifest, undefined, reordered.manifest)).toEqual(+ [],+ );+ expect(unreviewedGhostPermissionItems(reviewed.manifest, undefined, narrowed.manifest)).toEqual(+ [],+ );+ expect(ghostNodeSecretAuthorizationWithinCap(reviewed.manifest, expanded.manifest)).toBe(false);+ expect(ghostNodeSecretAuthorizationWithinCap(reviewed.manifest, changedUrl.manifest)).toBe(false);+ });+it('语义相同时指纹稳定(与字段/条目顺序无关)', () => {const a = validateGhostManifest(goodChipManifest());const b = validateGhostManifest(JSON.parse(JSON.stringify(goodChipManifest())));diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex 3ac7225c8f..be31d0ad0a 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -2458,6 +2458,10 @@ export function unreviewedGhostPermissionItems(const previewApproved =previewWithinCap(reviewed) ||(previouslyInstalled !== undefined && previewWithinCap(previouslyInstalled));+ const nodeSecretsApproved =+ ghostNodeSecretAuthorizationWithinCap(reviewed, actual) ||+ (previouslyInstalled !== undefined &&+ ghostNodeSecretAuthorizationWithinCap(previouslyInstalled, actual));return ghostPermissionItems(actual).filter((item) =>!approved.has(ghostPermissionProjectionKey(item)) &&@@ -2466,10 +2470,37 @@ export function unreviewedGhostPermissionItems(!(item.key === 'code' && approvedKeys.has(item.key)) &&// preview 的展示 detail 包含完整 hosts;真实包删减 host 是收权,不应因// detail 字符串变化被反判成新增能力。新增或替换 host 仍会保留为未审查项。- !(item.key === 'preview' && previewApproved),+ !(item.key === 'preview' && previewApproved) &&+ // Node secret 的展示 key 带完整 methods;换序或收窄是收权。URL/hint 与+ // entry 等 Host 实际消费字段由专用上限比较守住,不能依赖展示投影相等。+ !(item.key.startsWith('node:secret:') && nodeSecretsApproved),);}+/** 市场清单对 Node Worker 凭证注入与配置引导的授权上限。 */+export function ghostNodeSecretAuthorizationWithinCap(+ reviewed: GhostManifest,+ actual: GhostManifest,+): boolean {+ const actualBindings = actual.node?.secretBindings ?? [];+ if (actualBindings.length === 0) return true;+ const reviewedNode = reviewed.node;+ if (!reviewedNode) return false;+ const reviewedBindings = reviewedNode.secretBindings ?? [];+ for (const binding of actualBindings) {+ const targetEntry = binding.entry ?? actual.node?.entry;+ const cap = reviewedBindings.find(+ (candidate) =>+ candidate.key === binding.key &&+ (candidate.entry ?? reviewedNode.entry) === targetEntry,+ );+ if (!cap || !binding.methods.every((method) => cap.methods.includes(method))) return false;+ if (binding.url !== undefined && binding.url !== cap.url) return false;+ if (binding.hint !== undefined && binding.hint !== cap.hint) return false;+ }+ return true;+}+/*** 市场清单对真实包的 network 授权语义上限。*