Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(preview): resolve encoded SVG image reference URLs
BlueSkyID666f044e77b7575
diff --git a/src/main/features/chat_attachments.ts b/src/main/features/chat_attachments.tsindex 439816cc..6ea8e197 100644--- a/src/main/features/chat_attachments.ts+++ b/src/main/features/chat_attachments.ts@@ -48,6 +48,7 @@ import { MAX_TEXT_FILE_BYTES } from '../util/file-size-limits';import * as os from 'node:os';import * as path from 'node:path';import * as crypto from 'node:crypto';+import { fileURLToPath, pathToFileURL } from 'node:url';import { isPathAllowed } from '../util/path-sandbox';import { chatAttachmentDir, chatAttachmentDraftDir, userChatAttachmentsDir } from '../paths';@@ -1006,6 +1007,7 @@ export function materializeLocalDisplaySvg(catch (error) { return { ok: false, code: 'not_found', error: 'not found', diagnosticCode: mediaFileFailureCode(error) }; }const root = path.dirname(resolved.absPath);+ const sourceUrl = pathToFileURL(resolved.absPath);let inlineError: { code: 'bad_input' | 'not_found' | 'too_large'; error: string; diagnosticCode?: MediaFileDiagnostic } | null = null;let refCount = 0;body = body.replace(@@ -1023,8 +1025,15 @@ export function materializeLocalDisplaySvg(inlineError = { code: 'bad_input', error: 'unsupported SVG image reference' };return full;}- const decodedRef = ref.replace(/&/g, '&');- const imageAbs = path.resolve(root, decodedRef);+ let imageAbs: string;+ try {+ // SVG hrefs are URLs: decode filename bytes once and keep query/fragment+ // outside the filesystem path before applying the existing confinement.+ imageAbs = fileURLToPath(new URL(ref.replace(/&/g, '&'), sourceUrl));+ } catch {+ inlineError = { code: 'bad_input', error: 'invalid SVG image reference' };+ return full;+ }const rel = path.relative(root, imageAbs);if (!rel || rel.startsWith('..') || path.isAbsolute(rel) || !isPathAllowed(imageAbs, [root])) {inlineError = { code: 'bad_input', error: 'SVG image reference escapes its directory' };diff --git a/test/main/features/chat_attachments.test.ts b/test/main/features/chat_attachments.test.tsindex 20cb1228..92a00348 100644--- a/test/main/features/chat_attachments.test.ts+++ b/test/main/features/chat_attachments.test.ts@@ -1126,6 +1126,44 @@ describe('chat_attachments › resolveLocalMediaPath', () => {fs.rmSync(sandbox, { recursive: true, force: true });});+ it.each([+ ['frame 01.png', 'frame%2001.png'],+ ['帧#01.png', '%E5%B8%A7%2301.png'],+ ['frame%20.png', 'frame%2520.png?revision=1'],+ ])('embeds the exact raster bytes named by the SVG URL %s', async (name, href) => {+ const mod = await loadMod();+ const directory = path.join(tmpDir, 'svg-urls');+ fs.mkdirSync(directory);+ const bytes = await makePng();+ fs.writeFileSync(path.join(directory, name), bytes);+ const file = path.join(directory, 'sheet.svg');+ const source = `<svg xmlns="http://www.w3.org/2000/svg"><image href="${href}"/></svg>`;+ fs.writeFileSync(file, source);++ const result = mod.materializeLocalDisplaySvg(file);+ expect(result.ok).toBe(true);+ if (!result.ok) return;+ expect(result.body).toBe(`<svg xmlns="http://www.w3.org/2000/svg"><image href="data:image/png;base64,${bytes.toString('base64')}"/></svg>`);+ expect(fs.readFileSync(file, 'utf8')).toBe(source);+ expect(fs.readFileSync(path.join(directory, name))).toEqual(bytes);+ });++ it.each(['%2e%2e/outside.png', '..%2foutside.png', 'broken%ZZ.png'])(+ 'rejects an escaping or malformed SVG URL %s without returning file bytes', async (href) => {+ const mod = await loadMod();+ const directory = path.join(tmpDir, 'svg-urls');+ fs.mkdirSync(directory);+ const bytes = await makePng();+ fs.writeFileSync(path.join(tmpDir, 'outside.png'), bytes);+ const file = path.join(directory, 'sheet.svg');+ fs.writeFileSync(file, `<svg xmlns="http://www.w3.org/2000/svg"><image href="${href}"/></svg>`);+ const result = mod.materializeLocalDisplaySvg(file);+ expect(result).toMatchObject({ ok: false, code: 'bad_input' });+ expect(result).not.toHaveProperty('body');+ expect(fs.readFileSync(path.join(tmpDir, 'outside.png'))).toEqual(bytes);+ },+ );+it.each(['<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>','<svg xmlns="http://www.w3.org/2000/svg"><foreignObject><div>unsafe</div></foreignObject></svg>',