Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 签名包同样恢复归档 mode,并写明该取舍的依据
zhanghengxdb29c750b3348
diff --git a/apps/desktop/src/main/cindy-brain/GhostManager.ts b/apps/desktop/src/main/cindy-brain/GhostManager.tsindex e186877862..afc9bdeaf1 100644--- a/apps/desktop/src/main/cindy-brain/GhostManager.ts+++ b/apps/desktop/src/main/cindy-brain/GhostManager.ts@@ -3756,13 +3756,6 @@ export class GhostManager {},): Promise<void> {await fs.promises.mkdir(stagingDir, { recursive: true });- // 已签名 / 已审核包**不**采纳归档声明的 mode:签名 statement 只覆盖- // (path, sha256, bytes),mode 不在其中(`buildStatement`)。恢复一个签名没- // 覆盖的 mode,等于把未认证的 central-directory 元数据当成已签名事实 ——- // 能篡改包字节的人可以在验签仍然通过的前提下翻转执行位。未签名包不存在- // 越过签名边界的问题,照常按声明恢复。待 statement 升 v2 把归一化后的 mode- // 签进去,这里再对签名包放开。- const honorArchivedModes = !opts.trust.publisherSigned && !opts.trust.reviewed;let totalBytes = 0;for (const entry of allEntries) {const relName = entry.name.slice(prefix.length);@@ -3780,10 +3773,17 @@ export class GhostManager {}await fs.promises.mkdir(path.dirname(dest), { recursive: true });await fs.promises.writeFile(dest, data);- if (honorArchivedModes) {- const mode = installedFileModeFromZip(entry.unixPermissions);- if (mode !== null) await fs.promises.chmod(dest, mode);- }+ // 签名与 mode 的关系是**有意如此**,别当成漏改:statement 只覆盖+ // (path, sha256, bytes),mode 不在其中,所以归档 mode 属未认证元数据。+ // 仍然采纳它,是因为在 `installedFileModeFromZip` 的钳位之后,能篡改包+ // 字节的攻击者只剩下「翻转 r / x 位」:内容改不了、文件增删不了(白名单+ // + 逐文件哈希)、特殊位剥掉、group/other 写位钳掉、owner 读写强制保留。+ // 去掉 +x 只是他本来就能造成的可用性破坏(改坏一字节即验签失败);加上+ // +x 作用在他无法选择内容的文件上,而执行流指向哪个文件由签名覆盖的+ // manifest 与插件自身代码决定 —— 拿不到代码执行。若日后有任何逻辑开始+ // 依赖 mode 做安全判断,这个前提就失效,届时须把归一化 mode 签进 statement。+ const mode = installedFileModeFromZip(entry.unixPermissions);+ if (mode !== null) await fs.promises.chmod(dest, mode);}if (opts.disabled) {await fs.promises.writeFile(path.join(stagingDir, DISABLED_MARKER_FILE), '');diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.tsindex 1e3223e811..f04faa8543 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts@@ -4718,10 +4718,11 @@ describe('GhostManager · Unix file permissions', () => {}});- it('signed packages do not restore archive modes the signature never covered', async () => {- // 签名 statement 只覆盖 (path, sha256, bytes);mode 不在其中。若照旧恢复,- // 能篡改包字节的人就能在验签仍然通过的前提下翻转执行位。所以已签名包一律- // 不采纳归档 mode —— 等 statement 升 v2 把归一化 mode 签进去再放开。+ it('signed packages restore declared modes too, with special bits stripped', async () => {+ // 有意如此:statement 只覆盖 (path, sha256, bytes),mode 属未认证元数据,但+ // 钳位后攻击者只剩「翻转 r / x 位」,拿不到代码执行(详见 extractToStaging+ // 的注释)。若哪天决定改成「签名包不采纳 mode」,这条用例会红 —— 那正是+ // 我们要的:这是个产品/安全决定,不该被静默改掉。const unsigned = await makeUnixModeCindy('signed-modes.cindy', goodManifest(), 'v1');const publisher = crypto.generateKeyPairSync('ed25519');const signed = await signGhostPackage(await fs.promises.readFile(unsigned), {@@ -4735,22 +4736,22 @@ describe('GhostManager · Unix file permissions', () => {const loaded = await JSZip.loadAsync(signed);expect(Number(loaded.files['bin/tool'].unixPermissions) & 0o777).toBe(0o755);- const chmodSpy = vi.spyOn(fs.promises, 'chmod');- try {- const installed = await manager.install(signedPath);- expect(installed).toHaveProperty('ghost');- expect((installed as { ghost: InstalledGhost }).ghost.trust?.publisherSigned).toBe(true);- expect(chmodSpy).not.toHaveBeenCalled();- } finally {- chmodSpy.mockRestore();- }- // 内容照常落盘,只是执行位不恢复(留在文件系统缺省)。+ const installed = await manager.install(signedPath);+ expect(installed).toHaveProperty('ghost');+ expect((installed as { ghost: InstalledGhost }).ghost.trust?.publisherSigned).toBe(true);+expect(await fs.promises.readFile(path.join(rootDir, 'hello', 'bin', 'tool'), 'utf8'),).toContain('v1');if (process.platform !== 'win32') {- expect((await fs.promises.stat(path.join(rootDir, 'hello', 'bin', 'tool'))).mode & 0o111)- .toBe(0);+ // 签名包与未签名包走同一条恢复路径:0755 保留、0644 保留、特殊位剥除。+ expect((await fs.promises.stat(path.join(rootDir, 'hello', 'bin', 'tool'))).mode & 0o777)+ .toBe(0o755);+ expect((await fs.promises.stat(path.join(rootDir, 'hello', 'config.txt'))).mode & 0o777)+ .toBe(0o644);+ const special = await fs.promises.stat(path.join(rootDir, 'hello', 'bin', 'special'));+ expect(special.mode & 0o777).toBe(0o755);+ expect(special.mode & 0o4000).toBe(0);}});