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(desktop): 修插件资格判据里 installed=false 反而提权的 fail-open

fmfsaisai325302e11a14
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostFirstPartyPrivilege.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostFirstPartyPrivilege.test.ts
index 7262cd013d..837438355e 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostFirstPartyPrivilege.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostFirstPartyPrivilege.test.ts
@@ -45,17 +45,25 @@ function market(
}
describe('resolveGhostFirstPartyPrivilege', () => {
- it('gives builtin official plugins broker and host primitives even with no ledger', () => {
- expect(resolveGhostFirstPartyPrivilege(facts({ ghostId: 'xd-feishu', builtin: true }))).toEqual({
- brokerEligible: true,
- hostPrimitiveEligible: true,
- basis: 'builtin-official',
- });
- expect(resolveGhostFirstPartyPrivilege(facts({ ghostId: 'xd-atlassian', builtin: true }))).toEqual({
- brokerEligible: true,
- hostPrimitiveEligible: true,
- basis: 'builtin-official',
- });
+ // 存量兼容红线(P0):随包的 xd-feishu / xd-atlassian 是全仓唯一声明 oauth.tokenBroker
+ // 的两个插件。用户切成个人身份、或从未打开过市场页(无台账)时,它们必须照旧拿到
+ // Broker 与宿主原语——退化了就是已装插件在升级后失效。
+ // `currentOrganization: null` 与 `marketRecord: null` 在这里**显式写出**,不吃
+ // `facts()` 的默认值:否则将来有人为省事把默认改成"有组织",这条依然会通过
+ // (优先级 1 本就不看 org),但"个人身份"这个场景就悄悄没人守了。
+ it('gives builtin official plugins broker and host primitives with no ledger and no organization', () => {
+ for (const ghostId of ['xd-feishu', 'xd-atlassian']) {
+ expect(
+ resolveGhostFirstPartyPrivilege(
+ facts({ ghostId, builtin: true, marketRecord: null, currentOrganization: null }),
+ ),
+ ghostId,
+ ).toEqual({
+ brokerEligible: true,
+ hostPrimitiveEligible: true,
+ basis: 'builtin-official',
+ });
+ }
});
it('denies bundled plugins that miss the static official table, including x-manager reclaimPort', () => {
@@ -234,6 +242,70 @@ describe('resolveGhostFirstPartyPrivilege', () => {
});
});
+ // 台账里有这条 id 但 installed 为 false 时,曾经会整段跳过市场分支、落到末尾那条
+ // 「本地包 + 本组织前缀 → 放行」的兜底。于是同一条 `scope: 'personal'` 记录
+ // (明确不可信)把 installed 从 true 改成 false,结论就从 deny 翻成 allow ——
+ // **把一个字段置 false 反而提权**,安全判据里的 fail-open。
+ // 而且这条路正是冒名场景:市场台账里已经有这个 id,本地却装了个同名手搓包。
+ it('does not let a not-installed ledger row fall through to the local-package tail', () => {
+ for (const scope of ['personal', 'public', 'organization'] as const) {
+ expect(
+ resolveGhostFirstPartyPrivilege(
+ facts({
+ ghostId: 'acme-feishu',
+ marketRecord: market({ scope, installed: false }),
+ currentOrganization: CURRENT_ORG,
+ }),
+ ),
+ scope,
+ ).toEqual({
+ brokerEligible: false,
+ hostPrimitiveEligible: false,
+ basis: 'denied-unknown-origin',
+ });
+ }
+ // 作者自测不受影响:从未发布过的 id 压根没有台账行(marketRecord 为 null),
+ // 照旧走到兜底并放行——这条在上面「local / custom-market」那条用例里钉着。
+ });
+
+ // `legacy-adopted` 是市场列表成功后为「早于市场就已装在本机的官方前缀插件」合成的
+ // 来源(`plugin-market/service.ts::adoptLegacyInstallations`)。判据对它一律 deny:
+ // 它既不是 `source: 'market'`(所以进不了 public 那支),也不是 git/local market。
+ //
+ // **今天这是空操作**,因为所有真正用到 Broker 或宿主原语的插件都是随包的
+ // (`xd-feishu` / `xd-atlassian` / `x-manager`),走优先级 1 的 builtin 分支,
+ // 根本到不了这里。但将来一旦有**非随包**的官方前缀插件要用这两类特权,
+ // 这条分支就会把它 fail-closed 掉——那时必须显式决策,不能当漏网 bug 顺手放宽。
+ it('denies legacy-adopted rows, which today only bundled plugins could hit', () => {
+ for (const scope of ['public', 'organization'] as const) {
+ expect(
+ resolveGhostFirstPartyPrivilege(
+ facts({
+ ghostId: 'cindy-art',
+ marketRecord: market({ scope, source: 'legacy-adopted' }),
+ currentOrganization: CURRENT_ORG,
+ }),
+ ),
+ scope,
+ ).toMatchObject({ brokerEligible: false, hostPrimitiveEligible: false });
+ }
+ // 同一个 id 只要 builtin 为真就走优先级 1,台账怎么写都不影响——这才是
+ // 随包插件今天的实际路径。
+ expect(
+ resolveGhostFirstPartyPrivilege(
+ facts({
+ ghostId: 'cindy-art',
+ builtin: true,
+ marketRecord: market({ scope: 'organization', source: 'legacy-adopted' }),
+ }),
+ ),
+ ).toEqual({
+ brokerEligible: true,
+ hostPrimitiveEligible: true,
+ basis: 'builtin-official',
+ });
+ });
+
it('fail-closes unknown origin, missing prefix, and unmatched prefix', () => {
expect(resolveGhostFirstPartyPrivilege(facts({ ghostId: 'mystery' }))).toEqual({
brokerEligible: false,
diff --git a/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts b/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
index f87f02c2e3..99efc0c1a0 100644
--- a/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostFirstPartyPrivilege.ts
@@ -119,7 +119,21 @@ export function resolveGhostFirstPartyPrivilege(facts: GhostFirstPartyFacts): Gh
}
const record = facts.marketRecord;
- if (record?.installed) {
+ if (record !== null) {
+ if (!record.installed) {
+ // A ledger row that exists but is not installed must not fall through to
+ // the local-package tail below. Two reasons, both mattering:
+ // 1. Fail-open direction. `{scope: 'personal', installed: true}` is
+ // denied here; flipping `installed` to false would have turned that
+ // same row into an allow via the tail. A security predicate must
+ // never grant more when one of its fields is false.
+ // 2. It is the impersonation case, not the self-test case. Once an id
+ // appears in the market ledger, a hand-built local package carrying
+ // that same id is impersonating it. Author self-test is unaffected:
+ // a never-published id has no ledger row at all (`marketRecord`
+ // is null) and still reaches the tail.
+ return deny('denied-unknown-origin');
+ }
if (record.scope === 'public' && record.source === 'market') {
return isOfficialGhostId(facts.ghostId)
? allow('market-public', true)