Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): refuse an unsupported image format at pick time
[._.]/ Adam Eivy94fe2e6bc361
diff --git a/client/src/components/shell/ShellImageDrop.test.jsx b/client/src/components/shell/ShellImageDrop.test.jsxindex c2e6c7cd3e..898db4a53e 100644--- a/client/src/components/shell/ShellImageDrop.test.jsx+++ b/client/src/components/shell/ShellImageDrop.test.jsx@@ -101,6 +101,25 @@ describe('ShellImageDrop', () => {expect(toastMock.error).toHaveBeenCalledWith(expect.stringContaining('not an image'));});+ // A drop or a clipboard paste bypasses the picker's `accept`, so an unsupported+ // image has to be caught here or it only fails after the message is typed.+ it('rejects an image format the server cannot verify, before it is previewed', () => {+ render(<ShellImageDrop onSend={vi.fn()} />);+ openComposer();+ const avif = imageFile('shot.avif', { type: 'image/avif' });+ fireEvent.drop(screen.getByLabelText('Message'), { dataTransfer: { files: [avif] } });+ expect(toastMock.error).toHaveBeenCalledWith(expect.stringContaining('supported: PNG, JPEG, GIF, WebP'));+ expect(screen.queryByAltText('shot.avif')).toBeNull();+ });++ it('accepts a dropped GIF (the server verifies it, even though the picker filters it out)', () => {+ render(<ShellImageDrop onSend={vi.fn()} />);+ openComposer();+ const gif = imageFile('loop.gif', { type: 'image/gif' });+ fireEvent.drop(screen.getByLabelText('Message'), { dataTransfer: { files: [gif] } });+ expect(screen.getByAltText('loop.gif')).toBeTruthy();+ });+it('accepts a pasted image', () => {render(<ShellImageDrop onSend={vi.fn()} />);openComposer();diff --git a/client/src/utils/fileUpload.js b/client/src/utils/fileUpload.jsindex b678229b05..585e2f8456 100644--- a/client/src/utils/fileUpload.js+++ b/client/src/utils/fileUpload.js@@ -82,12 +82,29 @@ export function readFileAsBase64(file) {}/**- * Gate a picked file as an uploadable image: right kind, within the size cap.+ * The image formats the upload endpoints can magic-byte verify — a mirror of+ * `detectImageFormat` in `server/lib/fileUtils.js`, which the client can't import.+ * Anything else is refused server-side with a 400, so the check has to exist here+ * too: a drag-drop or a clipboard paste bypasses the picker's `accept` entirely,+ * and without this an AVIF or SVG previews happily and only fails AFTER the user+ * has typed their message. `uploadLimits.test.js` guards the two lists against+ * drift.*- * Every image picker in the app needs this pair of checks, and a surface that- * PREVIEWS before uploading (the Shell photo composer) can't get it from- * `processScreenshotUploads`, which uploads immediately. So it lives here and- * both call it, keeping one wording for the size-limit message.+ * Distinct from `IMAGE_ACCEPT`, which is narrower on purpose (no GIF) because its+ * consumers feed image-gen backends rather than this upload pipeline.+ */+export const SUPPORTED_UPLOAD_IMAGE_MIME = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];++const SUPPORTED_LABEL = 'PNG, JPEG, GIF, WebP';++/**+ * Gate a picked file as an uploadable image: a format the server accepts, within+ * the size cap.+ *+ * Every image picker in the app needs these checks, and a surface that PREVIEWS+ * before uploading (the Shell photo composer) can't get them from+ * `processScreenshotUploads`, which uploads immediately. So it lives here and both+ * call it, keeping one wording for the messages.** @param {File} file* @param {number} [maxFileSize] - byte ceiling (default: the screenshot cap)@@ -95,6 +112,9 @@ export function readFileAsBase64(file) {*/export function validateImageFile(file, maxFileSize = SCREENSHOT_MAX_FILE_SIZE) {if (!file?.type?.startsWith('image/')) return `File "${file?.name}" is not an image`;+ if (!SUPPORTED_UPLOAD_IMAGE_MIME.includes(file.type)) {+ return `File "${file.name}" is a ${file.type.replace('image/', '').toUpperCase()} — supported: ${SUPPORTED_LABEL}`;+ }if (file.size > maxFileSize) return `File "${file.name}" exceeds the ${formatBytes(maxFileSize)} limit`;return null;}diff --git a/server/lib/uploadLimits.test.js b/server/lib/uploadLimits.test.jsindex 393f82abc3..276763ab4f 100644--- a/server/lib/uploadLimits.test.js+++ b/server/lib/uploadLimits.test.js@@ -8,6 +8,7 @@ import {MAX_BASE64_UPLOAD_BYTES,MAX_SCREENSHOT_BYTES,} from './uploadLimits.js';+import { detectImageFormat } from './fileUtils.js';const HERE = dirname(fileURLToPath(import.meta.url));const read = (p) => readFileSync(join(HERE, p), 'utf8');@@ -110,6 +111,30 @@ describe('uploadLimits', () => {}});+ it('matches the client mirror of the supported image formats', () => {+ // The client refuses an unsupported image at pick time — a drag-drop or a+ // clipboard paste bypasses the picker's `accept`, so without a client-side+ // check an AVIF/SVG only fails after the user typed their message. That list+ // mirrors `detectImageFormat` here, which the client can't import; if the+ // server learns a new format and the mirror doesn't, the client rejects+ // something the server would happily accept.+ const clientSrc = read('../../client/src/utils/fileUpload.js');+ const match = clientSrc.match(/SUPPORTED_UPLOAD_IMAGE_MIME = \[([^\]]*)\]/);+ expect(match, 'client mirror not found — did SUPPORTED_UPLOAD_IMAGE_MIME move?').toBeTruthy();+ const mirrored = [...match[1].matchAll(/'([^']+)'/g)].map((m) => m[1]).sort();++ // Derive the server's set from detectImageFormat itself rather than restating+ // it, so this compares behavior and not two copies of a literal.+ const png = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);+ const jpeg = Buffer.from([0xff, 0xd8, 0xff, 0, 0, 0, 0, 0]);+ const gif = Buffer.from([0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0, 0]);+ const webp = Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WEBP')]);+ const supported = [png, jpeg, gif, webp].map((b) => detectImageFormat(b)?.mime);+ expect(supported, 'a probe stopped matching detectImageFormat').not.toContain(undefined);++ expect(mirrored).toEqual([...new Set(supported)].sort());+ });+it('matches the client mirror of the screenshot cap', () => {// Screenshots have their own (smaller, product-chosen) cap. It is mirrored// client-side too, so it needs the same drift guard as the wire limit —diff --git a/server/services/shell.js b/server/services/shell.jsindex f61b020d90..1a6cbe66f2 100644--- a/server/services/shell.js+++ b/server/services/shell.js@@ -567,6 +567,14 @@ const PASTE_SUBMIT_DELAY_MS = 400;* `agentTuiSpawning.js` retries against a paste-marker probe. Don't grow this* function into that; reach for those.*+ * The return value reports that the paste was WRITTEN, deliberately not that the+ * TUI submitted it — the submitting Enter is fire-and-forget. Making it awaitable+ * would delay every caller's response by `PASTE_SUBMIT_DELAY_MS` to cover only the+ * case where the PTY dies inside that window, which the user is already watching+ * happen in the terminal (`shell:exit` paints "[Shell exited…]"). This is the same+ * contract `shell:input` has for ordinary keystrokes: delivery to the PTY is what+ * is promised.+ ** @param {string} sessionId* @param {string} text - paste payload (no trailing newline; the Enter submits it)* @param {object} [opts]