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: re-anchor codex initImagePath via resolveGalleryImage
[._.]/ Adam Eivy453256912c62
diff --git a/server/services/imageGen/codex.js b/server/services/imageGen/codex.jsindex df7e93b5ad..8b30d2ff0c 100644--- a/server/services/imageGen/codex.js+++ b/server/services/imageGen/codex.js@@ -24,7 +24,7 @@ import { existsSync } from 'fs';import { join } from 'path';import { homedir } from 'os';import { randomUUID } from 'crypto';-import { ensureDir, PATHS } from '../../lib/fileUtils.js';+import { ensureDir, PATHS, resolveGalleryImage } from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import { imageGenEvents } from '../imageGenEvents.js';import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '../../lib/sseUtils.js';@@ -146,6 +146,13 @@ export async function generateImage({}await ensureDir(PATHS.images);+ // Defense-in-depth: HTTP routes already resolve basenames to absolute paths,+ // but re-anchor here so any future caller can't attach an arbitrary local+ // file via the codex CLI's `-i` flag. Mirrors imageGen/local.js.+ const validInitImagePath = (initImagePath && typeof initImagePath === 'string')+ ? resolveGalleryImage(initImagePath)+ : null;+const jobId = providedJobId || randomUUID();const filename = `${jobId}.png`;const outputPath = join(PATHS.images, filename);@@ -158,7 +165,7 @@ export async function generateImage({const sizeHint = (width && height) ? ` (${width}x${height})` : '';const qualityHint = (width >= 1536 || height >= 1536) ? ' (high quality)' : '';const avoidHint = negativePrompt?.trim() ? `\nAvoid: ${negativePrompt.trim()}` : '';- const editPrefix = initImagePath+ const editPrefix = validInitImagePath? `Edit the attached reference image — ${describeFidelity(initImageStrength)}. Render target:\n`: '';const fullPrompt = `$imagegen ${editPrefix}${prompt.trim()}${sizeHint}${qualityHint}${avoidHint}`;@@ -168,7 +175,7 @@ export async function generateImage({'exec','--skip-git-repo-check','--sandbox', 'workspace-write',- ...(initImagePath ? ['-i', initImagePath] : []),+ ...(validInitImagePath ? ['-i', validInitImagePath] : []),...(model ? ['-m', String(model)] : []),fullPrompt,];diff --git a/server/services/imageGen/codex.test.js b/server/services/imageGen/codex.test.jsindex ab8cc67da9..558f7601a2 100644--- a/server/services/imageGen/codex.test.js+++ b/server/services/imageGen/codex.test.js@@ -46,9 +46,13 @@ vi.mock('child_process', async (importOriginal) => {const FAKE_IMAGES_DIR = join(TEST_HOME, 'data-images');vi.mock('../../lib/fileUtils.js', async () => {const actual = await vi.importActual('../../lib/fileUtils.js');+ // Mutate the actual PATHS object so functions inside fileUtils.js+ // (e.g. resolveGalleryImage) see the test images dir at call time —+ // a spread-only override would leave the original PATHS.images intact+ // for any function closing over the actual module's binding.+ actual.PATHS.images = FAKE_IMAGES_DIR;return {...actual,- PATHS: { ...actual.PATHS, images: FAKE_IMAGES_DIR },ensureDir: vi.fn(async (dir) => mkdir(dir, { recursive: true })),};});@@ -133,16 +137,19 @@ describe('codex provider — generateImage', () => {});it('forwards initImagePath via `-i <FILE>` and reshapes the prompt for image-edit', async () => {+ // resolveGalleryImage requires the file to exist under PATHS.images.+ await mkdir(FAKE_IMAGES_DIR, { recursive: true });+ await writeFile(join(FAKE_IMAGES_DIR, 'proof.png'), 'fake');await codex.generateImage({prompt: 'cover art',width: 1024, height: 1536,- initImagePath: '/abs/path/to/proof.png',+ initImagePath: 'proof.png',initImageStrength: 0.2,});const { args } = spawnCalls[0];const iIdx = args.indexOf('-i');expect(iIdx).toBeGreaterThan(-1);- expect(args[iIdx + 1]).toBe('/abs/path/to/proof.png');+ expect(args[iIdx + 1]).toBe(join(FAKE_IMAGES_DIR, 'proof.png'));const promptArg = args[args.length - 1];// The `$imagegen` prefix is preserved so the bundled skill still triggers.expect(promptArg.startsWith('$imagegen ')).toBe(true);@@ -156,6 +163,23 @@ describe('codex provider — generateImage', () => {await flush();});+ it('drops initImagePath that escapes the gallery (defense-in-depth)', async () => {+ await codex.generateImage({+ prompt: 'cover art',+ // Absolute outside-gallery path — resolveGalleryImage rejects via basename.+ initImagePath: '/etc/passwd',+ initImageStrength: 0.2,+ });+ const { args } = spawnCalls[0];+ expect(args).not.toContain('-i');+ const promptArg = args[args.length - 1];+ // No edit prefix when the init image is dropped.+ expect(promptArg).not.toMatch(/edit the attached reference image/i);+ spawnCalls[0].child.exitCode = 1;+ spawnCalls[0].child.emit('close', 1, null);+ await flush();+ });+it('omits `-i` and the edit-prefix when no initImagePath is passed', async () => {await codex.generateImage({ prompt: 'cover art', width: 1024, height: 1024 });const { args } = spawnCalls[0];