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(media): accept case-insensitive URL schemes

Zhao Dengfeng589093036438
diff --git a/packages/maker-shared/src/__tests__/richAnswer.test.ts b/packages/maker-shared/src/__tests__/richAnswer.test.ts
index 38f37e8f2e..6227f2817c 100644
--- a/packages/maker-shared/src/__tests__/richAnswer.test.ts
+++ b/packages/maker-shared/src/__tests__/richAnswer.test.ts
@@ -1,6 +1,6 @@
import { youtubeVideo } from '../richAnswer';
import { describe, expect, it } from 'vitest';
-import { RichAnswerStream, RichInteractionMemory, hasRichAnswer, splitRichAnswer, richDefaults, richEvaluate, richLabel, richResolvedValues, richChart, richCalculationUnavailable, richVisualStyle, richVector, richLinePlot, type RichPalette } from '../richAnswer';
+import { RichAnswerStream, RichInteractionMemory, hasRichAnswer, splitRichAnswer, richDefaults, richEvaluate, richLabel, richResolvedValues, richChart, richCalculationUnavailable, richVisualStyle, richVector, richLinePlot, richMediaSource, type RichPalette } from '../richAnswer';
// Tier 1: actual stream reducer. Regression targets are partial transport, edits,
// replay and preservation of user input; no DOM/source-string contracts.
const line = (seq: number, op: Record<string, unknown>) => JSON.stringify({ seq, ...op }) + '\n';
@@ -216,6 +216,18 @@ it("keeps small-valued axes distinguishable and dense dates on the same coordina
).toBeLessThanOrEqual(0);
});
+// Unit: RFC 3986 schemes are case-insensitive. Existing media coverage missed
+// case normalization; only the scheme may change, and unsafe schemes stay denied.
+it.each([
+ ['HTTPS://Example.test/Media/Image.PNG?Token=Aa%2Bb#Preview', 'https://Example.test/Media/Image.PNG?Token=Aa%2Bb#Preview'],
+ ['CINDY-MEDIA://blobs/AbC123.PNG?Token=Aa%2Bb#Preview', 'cindy-media://blobs/AbC123.PNG?Token=Aa%2Bb#Preview'],
+])('normalizes only the allowed scheme in %s', (src, expected) => {
+ expect(richMediaSource({ id: 'media', kind: 'image', props: { src }, children: [] })).toBe(expected);
+});
+it.each(['JaVaScRiPt:alert(1)', 'DaTa:text/html;base64,PHNjcmlwdD4='])('rejects unsafe media scheme %s', src => {
+ expect(richMediaSource({ id: 'media', kind: 'image', props: { src }, children: [] })).toBeNull();
+});
+
// Unit: the reported YouTube watch URL used to reach the file player. Existing
// media tests cover file URLs only; verify host routing and the navigation boundary.
it('routes YouTube pages to canonical players without turning arbitrary URLs into embeds', () => {
diff --git a/packages/maker-shared/src/richAnswer.ts b/packages/maker-shared/src/richAnswer.ts
index dc3a6c8bad..ead65ca67c 100644
--- a/packages/maker-shared/src/richAnswer.ts
+++ b/packages/maker-shared/src/richAnswer.ts
@@ -955,13 +955,14 @@ export function compactRichAnswer(source: string): string {
export function richMediaSource(node: RichNode): string | null {
const src = richString(node, "src").trim();
if (!src || /[\r\n]/.test(src)) return null;
+ const allowed = /^(https?|file|xdt-(?:file|image|video|audio)|cindy-(?:remote-)?media):\/\//i.exec(src);
if (
/^[a-zA-Z][\w+.-]*:/.test(src) &&
!/^[a-zA-Z]:[\\/]/.test(src) &&
- !/^(https?:\/\/|file:\/\/|xdt-(?:file|image|video|audio):\/\/|cindy-(?:remote-)?media:\/\/)/.test(
- src,
- )
+ !allowed
)
return null;
- return src;
+ return allowed
+ ? allowed[1].toLowerCase() + src.slice(allowed[1].length)
+ : src;
}