Skip to content

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

address review (codex): sanitize availability filename + clear stale regenInfo

Adam Eivy445d4a01c349
diff --git a/client/src/pages/MediaAnnotate.jsx b/client/src/pages/MediaAnnotate.jsx
index 1337d09aca..70cf44da25 100644
--- a/client/src/pages/MediaAnnotate.jsx
+++ b/client/src/pages/MediaAnnotate.jsx
@@ -58,6 +58,11 @@ export default function MediaAnnotate() {
useEffect(() => {
if (!isImage) return;
let active = true;
+ // Clear synchronously on every image change: React Router reuses this page
+ // across :mediaKey changes, so a leftover regenInfo would otherwise disclose
+ // the PREVIOUS image's model/bounds until the new (possibly slow) probe
+ // resolves — letting the dialog open on stale availability.
+ setRegenInfo(null);
// Pass the source filename so the reported model is the exact one a regen of
// THIS image would run (multi-model installs), keeping the dialog honest.
getRegenAvailability(parsed?.ref)
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index 970a5272bd..1a037e9e6f 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -35,7 +35,7 @@ import {
import { PATHS, ensureDir, resolveGalleryImage } from '../lib/fileUtils.js';
import { prepareGenerateParams } from '../services/imageGen/prepareParams.js';
import { applyImageClean, applyWatermarkRemoval, applyLightRegenVariant } from '../services/imageGen/variants.js';
-import { join } from 'node:path';
+import { join, basename } from 'node:path';
import { STYLE_PRESETS } from '../lib/writersRoomStylePresets.js';
import {
resolveRegenBackend, getRegenAvailability, readImageDimensions, buildRegenParams,
@@ -309,9 +309,14 @@ router.get('/active', asyncHandler(async (_req, res) => {
// the annotate re-render dialog must disclose the real model before the render.
router.get('/regen/availability', asyncHandler(async (req, res) => {
const rawFilename = req.query.filename;
+ const galleryPath = typeof rawFilename === 'string' && rawFilename ? resolveGalleryImage(rawFilename) : null;
let sourceModelId;
- if (typeof rawFilename === 'string' && rawFilename && resolveGalleryImage(rawFilename)) {
- const { metadata } = await local.readImageSidecar(rawFilename);
+ if (galleryPath) {
+ // Read the sidecar by the RESOLVED gallery path's basename, never the raw
+ // query value: resolveGalleryImage only validated the basename, so a
+ // `../foo.png` input could otherwise traverse out of PATHS.images in the
+ // sidecar read. basename(galleryPath) is the sanitized filename.
+ const { metadata } = await local.readImageSidecar(basename(galleryPath));
sourceModelId = metadata?.modelId;
}
res.json(await getRegenAvailability({ sourceModelId }));
diff --git a/server/routes/imageGen.test.js b/server/routes/imageGen.test.js
index 89ece6a6a9..b365a51d81 100644
--- a/server/routes/imageGen.test.js
+++ b/server/routes/imageGen.test.js
@@ -1119,10 +1119,13 @@ describe('Image Gen Routes', () => {
const availSpy = vi.spyOn(regen, 'getRegenAvailability')
.mockResolvedValueOnce({ available: true, modelId: 'flux2-klein-9b', strengthMin: 0.02, strengthMax: 0.6, strengthDefault: 0.25 });
- const response = await request(app).get('/api/image-gen/regen/availability?filename=source.png');
+ // A path-prefixed query value must never reach the sidecar read raw — the
+ // sidecar is read by the RESOLVED gallery path's basename (traversal-safe).
+ const response = await request(app).get('/api/image-gen/regen/availability?filename=..%2F..%2Fsource.png');
expect(response.status).toBe(200);
expect(response.body.modelId).toBe('flux2-klein-9b');
+ expect(imageGen.local.readImageSidecar).toHaveBeenCalledWith('source.png');
// The source model must reach the availability resolver, or the dialog can
// name a different model than the POST enqueues on a multi-model install.
expect(availSpy).toHaveBeenCalledWith({ sourceModelId: 'flux2-klein-9b' });