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: constrain fine-tuning job ids and validate the recovered record shape (#5664)
Adam Eivy165ff5da9015
diff --git a/server/routes/voice.js b/server/routes/voice.jsindex da2b843183..d49a91919c 100644--- a/server/routes/voice.js+++ b/server/routes/voice.js@@ -247,7 +247,10 @@ const fineTuneStartSchema = z.object({const fineTuneJobParamsSchema = z.object({id: z.string().trim().regex(/^[a-z0-9][a-z0-9-]{0,79}$/),- jobId: z.string().trim().min(1).max(80),+ // Job ids are minted with randomUUID and are joined into a filesystem path+ // when the run is resolved from its on-disk record, so anything that could+ // carry a separator or `..` is rejected here.+ jobId: z.string().trim().uuid(),}).strict();const fineTunePromoteSchema = z.object({diff --git a/server/routes/voice.test.js b/server/routes/voice.test.jsindex ad30402072..47d7c78c99 100644--- a/server/routes/voice.test.js+++ b/server/routes/voice.test.js@@ -203,26 +203,35 @@ describe('Voice Routes', () => {});it('manages fine-tuning lifecycle: start, status, cancel, promote', async () => {- fineTuning.startFineTuningJob.mockResolvedValue({ jobId: 'job-1', status: 'running' });- fineTuning.getFineTuningJobStatus.mockReturnValue({ jobId: 'job-1', status: 'completed', checkpoints: [{ id: 'ckpt-1' }] });- fineTuning.cancelFineTuningJob.mockReturnValue({ ok: true, jobId: 'job-1', status: 'cancelled' });+ const jobId = '11111111-2222-4333-8444-555555555555';+ fineTuning.startFineTuningJob.mockResolvedValue({ jobId, status: 'running' });+ fineTuning.getFineTuningJobStatus.mockResolvedValue({ jobId, status: 'completed', checkpoints: [{ id: 'ckpt-1' }] });+ fineTuning.cancelFineTuningJob.mockReturnValue({ ok: true, jobId, status: 'cancelled' });fineTuning.promoteCheckpoint.mockResolvedValue({ id: 'voice-profile-1', kind: 'fine-tuned' });const startRes = await request(buildApp()).post('/api/voice/profiles/voice-profile-1/fine-tune/start').send({ epochs: 5 });expect(startRes.status).toBe(202);- const statusRes = await request(buildApp()).get('/api/voice/profiles/voice-profile-1/fine-tune/job-1');+ const statusRes = await request(buildApp()).get(`/api/voice/profiles/voice-profile-1/fine-tune/${jobId}`);expect(statusRes.status).toBe(200);expect(statusRes.body.status).toBe('completed');+ expect(fineTuning.getFineTuningJobStatus).toHaveBeenCalledWith(jobId, 'voice-profile-1');- const cancelRes = await request(buildApp()).post('/api/voice/profiles/voice-profile-1/fine-tune/job-1/cancel').send({});+ const cancelRes = await request(buildApp()).post(`/api/voice/profiles/voice-profile-1/fine-tune/${jobId}/cancel`).send({});expect(cancelRes.status).toBe(200);- const promoteRes = await request(buildApp()).post('/api/voice/profiles/voice-profile-1/fine-tune/job-1/promote').send({ checkpointId: 'ckpt-1' });+ const promoteRes = await request(buildApp()).post(`/api/voice/profiles/voice-profile-1/fine-tune/${jobId}/promote`).send({ checkpointId: 'ckpt-1' });expect(promoteRes.status).toBe(200);expect(promoteRes.body.profile.kind).toBe('fine-tuned');});+ it('rejects a fine-tuning job id that could escape the profile directory', async () => {+ const res = await request(buildApp())+ .get('/api/voice/profiles/voice-profile-1/fine-tune/..%2F..%2Fother-profile');+ expect(res.status).toBe(400);+ expect(fineTuning.getFineTuningJobStatus).not.toHaveBeenCalled();+ });+it('probes Qwen3 runtime status and downloads model on demand', async () => {qwen3TtsRuntime.getQwen3RuntimeStatus.mockResolvedValue({ ok: true, installed: true });qwen3TtsRuntime.downloadQwen3Model.mockResolvedValue({ ok: true, modelId: 'Qwen/Qwen3-TTS-12Hz-1.7B-VoiceDesign' });diff --git a/server/services/voice/fineTuning.js b/server/services/voice/fineTuning.jsindex 9564765e7b..0c361141f6 100644--- a/server/services/voice/fineTuning.js+++ b/server/services/voice/fineTuning.js@@ -38,9 +38,26 @@ const activeJobs = new Map();// together, rather than in a separate store that could outlive them.const JOB_RECORD_FILE = 'job.json';+// Job ids are minted with randomUUID; anything else never named a real run and+// must not reach `join`, where a separator or `..` would escape the profile's+// directory. Enforced here as well as in the route schema because this path is+// built from a caller-supplied id.+const JOB_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;+const jobRecordPath = (profileId, jobId) =>join(profileArtifactDirectory(profileId), 'fine-tune', jobId, JOB_RECORD_FILE);+// A record that parsed but is not shaped like a job (a truncated `{}`, a `null`,+// a hand-edited file) is not a usable recovery — it must not masquerade as a+// live job whose `checkpoints` a caller is about to `.find` over.+const isJobRecord = (record) => Boolean(+ record+ && typeof record === 'object'+ && typeof record.id === 'string'+ && typeof record.status === 'string'+ && Array.isArray(record.checkpoints)+);+// Drops the runtime-only handles (abort controller, child process, write chain,// finalize latch) that cannot — and must not — be serialized.const serializableJob = ({@@ -71,9 +88,9 @@ const persistJob = (jobState) => {async function loadJob(jobId, profileId) {const active = activeJobs.get(jobId);if (active) return active;- if (!profileId) return null;+ if (!profileId || !JOB_ID_RE.test(jobId)) return null;const { ok, value } = await readJSONFileStrict(jobRecordPath(profileId, jobId), null);- if (!ok) {+ if (!ok || (value !== null && !isJobRecord(value))) {throw new ServerError('Fine-tuning job record is unreadable', {status: 500,code: 'JOB_RECORD_UNREADABLE',diff --git a/server/services/voice/fineTuning.test.js b/server/services/voice/fineTuning.test.jsindex 876fde8dfb..f22bfa75f5 100644--- a/server/services/voice/fineTuning.test.js+++ b/server/services/voice/fineTuning.test.js@@ -205,6 +205,12 @@ describe('fineTuning', () => {const restarted = await import('./fineTuning.js');await expect(restarted.getFineTuningJobStatus(jobId, PROFILE.id)).rejects.toMatchObject({ code: 'JOB_RECORD_UNREADABLE' });++ // Parsing cleanly is not enough — a record without the job shape would let+ // promoteCheckpoint blow up on `job.checkpoints.find`.+ await writeFile(jobRecordPath(jobId), '{}');+ await expect(restarted.getFineTuningJobStatus(jobId, PROFILE.id))+ .rejects.toMatchObject({ code: 'JOB_RECORD_UNREADABLE' });});it('evicts the in-memory job entry after the grace window and keeps serving from disk', async () => {