The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): refuse SVG and ICO images instead of attaching a blob: URL
dokterdok5b6dad2a9bbc
diff --git a/apps/desktop/src/lib/browser-staged-attachments.test.ts b/apps/desktop/src/lib/browser-staged-attachments.test.tsindex 45ef04ede90..17680b99504 100644--- a/apps/desktop/src/lib/browser-staged-attachments.test.ts+++ b/apps/desktop/src/lib/browser-staged-attachments.test.ts@@ -315,6 +315,37 @@ describe('browser staged attachment transport', () => {])})+ // An SVG or ICO has no host path the send can read: a drop or paste of one is refused with the+ // reason, never left as an image chip pointing at a blob: URL.+ it.each([+ ['drop', new File(['<svg xmlns="http://www.w3.org/2000/svg"/>'], 'logo.svg', { type: 'image/svg+xml' })],+ ['paste', new Blob([new Uint8Array([0, 0, 1, 0])], { type: 'image/x-icon' })]+ ] as const)('refuses a %s of an image the browser cannot send and says why', async (flow, image) => {+ const fetchMock = await installBrowser()+ const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:http://127.0.0.1:9120/image')++ const { result } = renderHook(() =>+ useComposerActions({ activeSessionId: null, currentCwd: '/workspace', requestGateway: vi.fn() })+ )++ let attached = true++ await act(async () => {+ attached = flow === 'drop'+ ? await result.current.attachDroppedItems([{ file: image as File, path: '' }])+ : await result.current.attachImageBlob(image)+ })++ expect(attached).toBe(false)+ expect($composerAttachments.get()).toEqual([])+ expect($notifications.get()).toContainEqual(expect.objectContaining({+ kind: 'error',+ message: "SVG and ICO images can't be attached in the browser. Attach a PNG, JPEG, GIF, WebP or BMP instead."+ }))+ expect(fetchMock).not.toHaveBeenCalled()+ expect(createObjectURL).not.toHaveBeenCalled()+ })+it.each([{ remote: false, terminalBackend: 'local', upload: false },{ remote: true, terminalBackend: 'local', upload: true },diff --git a/apps/desktop/src/lib/browser-uploads.ts b/apps/desktop/src/lib/browser-uploads.tsindex bafcd14bb72..3c0bbc25867 100644--- a/apps/desktop/src/lib/browser-uploads.ts+++ b/apps/desktop/src/lib/browser-uploads.ts@@ -20,6 +20,11 @@ const IMAGE_MIME_BY_EXTENSION: Record<string, string> = {'.webp': 'image/webp'}+// Image types the composer attaches but the browser cannot stage: /api/chat/image-upload+// takes only the raster formats it can sniff, and the send reads an image chip+// back from that host path. A blob: URL here would become a chip whose Send fails.+const UNSENDABLE_IMAGE_EXTENSIONS = new Set(['.ico', '.svg'])+export const IMAGE_EXTENSION_BY_MIME: Record<string, string> = Object.fromEntries(Object.entries(IMAGE_MIME_BY_EXTENSION).map(([extension, mime]) => [mime, extension]))@@ -243,6 +248,10 @@ export function createBrowserUploadsBridge({const extension = normalizedExtension(ext)const imageMime = IMAGE_MIME_BY_EXTENSION[extension]+ if (UNSENDABLE_IMAGE_EXTENSIONS.has(extension)) {+ throw new Error("SVG and ICO images can't be attached in the browser. Attach a PNG, JPEG, GIF, WebP or BMP instead.")+ }+// /api/chat/image-upload stores images up to 25 MiB, but the send reads the staged image back// with the 16 MiB file-read cap: refuse a larger one here, before it shows as attached.if (imageMime && bytes.byteLength > BROWSER_UPLOAD_MAX_BYTES) {