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(chat): decode relative reply file hrefs through shared path guards

ylliuuu660be782efb169
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
index 5be8080e64..60a93a895b 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts
@@ -77,6 +77,20 @@ describe('group reply file delivery', () => {
expect((await result.attachments[0]!.readBytes!()).toString()).toBe('percent report');
});
+ it.each(['final report 中文.pdf', 'encoded%20.pdf', '100% done.pdf'])('decodes relative file hrefs once or preserves malformed percents: %s', async name => {
+ const dir = path.join(work, 'reports');
+ await fs.mkdir(dir, { recursive: true });
+ await fs.writeFile(path.join(dir, name), 'relative report');
+ const href = `reports/${name.startsWith('100') ? name : encodeURIComponent(name)}`;
+ const result = await prepareChatReplyFiles(`[report](<${href}>)`, 'lane', () => {});
+ expect(result.attachments).toHaveLength(1);
+ expect((await result.attachments[0]!.readBytes!()).toString()).toBe('relative report');
+ });
+
+ it.each(['reports%2Ffinal.pdf', 'reports%5Cfinal.pdf', 'reports/%2e%2e/report.pdf', '%68ttps%3A%2F%2Fexample.test/a.pdf', '%2F%2Fserver/a.pdf', 'reports/%00.pdf'])('refuses path syntax introduced by href decoding: %s', async href => {
+ await expect(prepareChatReplyFiles(`[report](${href})`, 'lane', () => {})).rejects.toThrow('ATTACHMENT_UNAVAILABLE');
+ });
+
it('leaves ordinary relative navigation targets unchanged without file authority', async () => {
scope.snapshot = null;
const text = '[help](about) [guide][nav]\n\n[nav]: getting-started';
diff --git a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
index ebe8b5dddf..edbccab59a 100644
--- a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts
@@ -12,6 +12,7 @@ import type { Definition } from 'mdast';
import { messages, sessions } from '../localDb/schema.js';
import { getCurrentDbClientSnapshot } from '../localDb/client/current.js';
import { visibleMessageText } from '../localDb/conversationSearch.pure.js';
+import { safeDecodeHrefForLookup } from '../pathResolver.js';
import { isPathWithin } from '../cindy-media/taskImageMarkdown.js';
import { BOT_GROUP_ATTACHMENTS_MAX } from '../../shared/botGroupChat.js';
import type { ChatUploadAttachment } from './chatServerMedia.js';
@@ -127,6 +128,11 @@ function localPath(url: string, workDir: string): string {
value = literal;
if (process.platform === 'win32' && /^\/[A-Za-z]:[\\/]/.test(value)) value = value.slice(1);
}
+ } else {
+ // Match ordinary Markdown lookup without decoding protocol/query paths twice.
+ const decoded = safeDecodeHrefForLookup(url);
+ if (decoded === null) throw unavailable();
+ value = decoded;
}
} catch { throw unavailable(); }
// Never resolve a network/device path, including on another host platform.
diff --git a/apps/desktop/src/main/pathResolver.ts b/apps/desktop/src/main/pathResolver.ts
index 3c7f8e7e81..9fba343926 100644
--- a/apps/desktop/src/main/pathResolver.ts
+++ b/apps/desktop/src/main/pathResolver.ts
@@ -75,7 +75,8 @@ function pathSegments(value: string): string[] {
return value.split(/[\\/]+/);
}
-function safeDecodeHrefForLookup(value: string): string | null {
+/** Decode href filename characters once without introducing path or URL syntax. */
+export function safeDecodeHrefForLookup(value: string): string | null {
let decoded: string;
try {
decoded = decodeURIComponent(value);