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
fix: reject protocol-relative image URLs + gate item PATCH to fixed type (#911)
Adam Eivya6ac3452f59d
diff --git a/server/lib/moodBoardValidation.js b/server/lib/moodBoardValidation.jsindex 8a8eaa67a9..7e6c1aa47b 100644--- a/server/lib/moodBoardValidation.js+++ b/server/lib/moodBoardValidation.js@@ -19,9 +19,11 @@ const mediaKeySchema = z.string().trim().min(3).max(512).regex(// External/pinned image URL. http(s) or a same-origin app path (e.g. a served// `/data/images/...` URL). Bounded; the UI renders it in an <img>, so no exotic-// schemes.+// schemes. A protocol-relative `//host/...` is rejected: it starts with `/` but+// resolves to an arbitrary external origin, which the leading-slash branch is+// not meant to allow.const imageUrlSchema = z.string().trim().min(1).max(2048).refine(- (v) => /^https?:\/\//.test(v) || v.startsWith('/'),+ (v) => /^https?:\/\//.test(v) || (v.startsWith('/') && !v.startsWith('//')),'imageUrl must be an http(s) URL or an absolute app path',);diff --git a/server/lib/moodBoardValidation.test.js b/server/lib/moodBoardValidation.test.jsindex c29edf2669..93983be8c4 100644--- a/server/lib/moodBoardValidation.test.js+++ b/server/lib/moodBoardValidation.test.js@@ -47,6 +47,9 @@ describe('moodBoardItemCreateSchema', () => {it('rejects a bad imageUrl scheme', () => {expect(moodBoardItemCreateSchema.safeParse({ type: 'image', imageUrl: 'javascript:alert(1)' }).success).toBe(false);});+ it('rejects a protocol-relative imageUrl', () => {+ expect(moodBoardItemCreateSchema.safeParse({ type: 'image', imageUrl: '//evil.com/x.png' }).success).toBe(false);+ });it('rejects a malformed mediaKey', () => {expect(moodBoardItemCreateSchema.safeParse({ type: 'image', mediaKey: 'no-colon' }).success).toBe(false);});diff --git a/server/services/moodBoard/logic.js b/server/services/moodBoard/logic.jsindex 5a61f800b1..9dc76447f1 100644--- a/server/services/moodBoard/logic.js+++ b/server/services/moodBoard/logic.js@@ -79,8 +79,12 @@ export function addItem(board, itemInput) {return { board: next, item };}-// PATCH a single item's editable fields (caption/source/text/imageUrl/mediaKey).-// Absent keys preserve; throws NOT_FOUND when the item id isn't on the board.+// PATCH a single item's editable fields. caption/source apply to any item;+// the body fields are gated to the item's FIXED type (an item's kind can't+// change after creation) so a patch can't make a text item carry an imageUrl+// or an image item carry text — the schema permits every key, the invariant is+// enforced here where the item's type is known. Absent keys preserve; throws+// NOT_FOUND when the item id isn't on the board.export function updateItem(board, itemId, patch) {const items = Array.isArray(board.items) ? board.items : [];const idx = items.findIndex((it) => it && it.id === itemId);@@ -89,7 +93,10 @@ export function updateItem(board, itemId, patch) {}const current = items[idx];const updated = { ...current };- for (const key of ['caption', 'source', 'text', 'imageUrl', 'mediaKey']) {+ const editableKeys = current.type === 'image'+ ? ['caption', 'source', 'imageUrl', 'mediaKey']+ : ['caption', 'source', 'text'];+ for (const key of editableKeys) {if (patch[key] !== undefined) updated[key] = patch[key];}const nextItems = [...items];diff --git a/server/services/moodBoard/logic.test.js b/server/services/moodBoard/logic.test.jsindex 0eccf0b015..42c98407dd 100644--- a/server/services/moodBoard/logic.test.js+++ b/server/services/moodBoard/logic.test.js@@ -90,6 +90,19 @@ describe('updateItem', () => {it('throws NOT_FOUND for an unknown item id', () => {expect(() => updateItem(withItem, 'nope', { caption: 'x' })).toThrow(/not found/i);});+ it('ignores type-inappropriate body fields (text item cannot gain an imageUrl)', () => {+ const { item } = updateItem(withItem, itemId, { imageUrl: 'https://x/y.png', mediaKey: 'image:a.png', text: 'changed' });+ expect(item.imageUrl).toBeNull();+ expect(item.mediaKey).toBeNull();+ expect(item.text).toBe('changed');+ });+ it('ignores text on an image item', () => {+ const { board } = addItem(buildBoardRecord({ name: 'A' }, { id: 'mb-2', now: 't0' }), { type: 'image', imageUrl: 'https://x/y.png' });+ const imgId = board.items[0].id;+ const { item } = updateItem(board, imgId, { text: 'nope', caption: 'ok' });+ expect(item.text).toBeNull();+ expect(item.caption).toBe('ok');+ });});describe('removeItem', () => {