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

fix: require operator authority for media process execution

[._.]/ Adam Eivy156a9e5edda3
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.js
index 2f4f7677b9..a5f9978243 100644
--- a/server/lib/hostControlRoutes.js
+++ b/server/lib/hostControlRoutes.js
@@ -476,6 +476,23 @@ export const HOST_CONTROL_ROUTES = Object.freeze([
'POST /api/midi-runtime/install',
'POST /api/devtools/video-download/yt-dlp/update',
+ // Video and audio downloads shell out to yt-dlp and ffmpeg on the host.
+ 'POST /api/devtools/video-download',
+ 'POST /api/tracks/import/youtube',
+ 'POST /api/rounds/reference-audio/import',
+
+ // Audio-to-MIDI transcription runs the local MuScriptor Python sidecar on the host.
+ 'POST /api/music-video/:id/transcribe-midi',
+ 'POST /api/rounds/reference-audio/transcribe-midi',
+
+ // Vocal stem separation provisions a demucs venv and runs neural separation on the host.
+ 'POST /api/music-video/:id/vocal-stem/separate',
+ // Lyric alignment downloads models and spawns whisper or neural CTC on the host.
+ 'POST /api/music-video/:id/lyrics/align',
+
+ // LoRA effect probe spawns Python on the host to analyze adapter tensors.
+ 'POST /api/loras/:filename/effect',
+
// Media authoring can launch a coding CLI/TUI agent, including via provider
// fallback. Gate the whole operation even when the initial provider is API;
// runtime-data cwd and later render containment do not sandbox authoring.
diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.js
index d17d307e59..ad7aac38e2 100644
--- a/server/lib/hostControlRoutes.test.js
+++ b/server/lib/hostControlRoutes.test.js
@@ -960,3 +960,48 @@ describe('Importer, Brain and analytics AI policy (#11036)', () => {
]) expect(isHostControlRoute(method, path), `${method} ${path}`).toBe(false);
});
});
+
+describe('Media process execution policy', () => {
+ const protectedRoutes = [
+ 'POST /api/devtools/video-download',
+ 'POST /api/tracks/import/youtube',
+ 'POST /api/rounds/reference-audio/import',
+ 'POST /api/music-video/:id/transcribe-midi',
+ 'POST /api/rounds/reference-audio/transcribe-midi',
+ 'POST /api/music-video/:id/vocal-stem/separate',
+ 'POST /api/music-video/:id/lyrics/align',
+ 'POST /api/loras/:filename/effect',
+ ];
+
+ it('gates each route and maps every entry to a mounted route', () => {
+ const mounted = new Set(getApiRouteCatalog().routes.map(({ method, path }) => method + ' ' + path));
+ for (const route of protectedRoutes) {
+ const [method, path] = route.split(' ');
+ expect(mounted.has(route), route).toBe(true);
+ expect(hostControlRouteFor(method, path), route).toBe(route);
+ expect(hostControlRouteFor(method, path.toUpperCase() + '/'), route).toBe(route);
+ }
+ });
+
+ it('keeps reads, progress SSE, and cancellations open', () => {
+ for (const [method, path] of [
+ ['GET', '/api/devtools/video-download/downloads'],
+ ['GET', '/api/devtools/video-download/yt-dlp'],
+ ['GET', '/api/devtools/video-download/:jobId/events'],
+ ['POST', '/api/devtools/video-download/:jobId/cancel'],
+ ['GET', '/api/tracks/import/:jobId/events'],
+ ['POST', '/api/tracks/import/:jobId/cancel'],
+ ['GET', '/api/rounds/reference-audio/import/:jobId/events'],
+ ['POST', '/api/rounds/reference-audio/import/:jobId/cancel'],
+ ['GET', '/api/rounds/reference-audio/transcribe-midi/:jobId/events'],
+ ['POST', '/api/rounds/reference-audio/transcribe-midi/:jobId/cancel'],
+ ['GET', '/api/music-video/:id/transcribe-midi/:jobId/events'],
+ ['POST', '/api/music-video/transcribe-midi/:jobId/cancel'],
+ ['GET', '/api/music-video/vocal-stem/separate/:jobId/events'],
+ ['POST', '/api/music-video/vocal-stem/separate/:jobId/cancel'],
+ ['GET', '/api/music-video/lyrics/align/:jobId/events'],
+ ['POST', '/api/music-video/lyrics/align/:jobId/cancel'],
+ ['GET', '/api/loras'],
+ ]) expect(isHostControlRoute(method, path), `${method} ${path}`).toBe(false);
+ });
+});
diff --git a/server/routes/hostControlMediaProcessing.test.js b/server/routes/hostControlMediaProcessing.test.js
new file mode 100644
index 0000000000..681c75cc99
--- /dev/null
+++ b/server/routes/hostControlMediaProcessing.test.js
@@ -0,0 +1,217 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { EventEmitter } from 'node:events';
+import express from 'express';
+import { request } from '../lib/testHelper.js';
+import { errorMiddleware } from '../lib/errorHandler.js';
+
+const state = vi.hoisted(() => ({ enabled: false }));
+const effects = vi.hoisted(() => ({
+ startVideoDownload: vi.fn(async () => ({ jobId: 'dl-1' })),
+ startYoutubeImport: vi.fn(async () => ({ jobId: 'yt-1' })),
+ startReferenceAudioImport: vi.fn(async () => ({ jobId: 'ref-1' })),
+ startMidiTranscription: vi.fn(async () => ({ jobId: 'midi-1', model: 'medium' })),
+ startVocalSeparation: vi.fn(async () => ({ jobId: 'vocal-1' })),
+ startLyricAlign: vi.fn(async () => ({ jobId: 'align-1' })),
+ probeLoraEffect: vi.fn(async () => ({ status: 'active' })),
+}));
+
+vi.mock('../services/auth.js', () => ({
+ isAuthEnabled: vi.fn(async () => state.enabled),
+ verifyRequestSession: vi.fn(async (req) => req.headers.authorization === 'Bearer example-session'),
+ verifyPassword: vi.fn(async () => true),
+}));
+
+vi.mock('../services/settings.js', () => ({
+ settingsEvents: new EventEmitter(),
+ getSettings: vi.fn(async () => ({})),
+}));
+
+vi.mock('../services/videoDownload.js', () => ({
+ startVideoDownload: effects.startVideoDownload,
+ listDownloads: vi.fn(async () => []),
+ deleteDownload: vi.fn(async () => ({ ok: true })),
+ cancelVideoDownload: vi.fn(() => ({ ok: true })),
+}));
+
+vi.mock('../services/ytdlpUpdate.js', () => ({
+ getYtDlpUpdateStatus: vi.fn(async () => ({ version: '2024.01.01' })),
+ updateYtDlp: vi.fn(async () => ({ success: true, version: '2024.01.02' })),
+}));
+
+vi.mock('../services/trackYoutubeImport.js', () => ({
+ startYoutubeImport: effects.startYoutubeImport,
+ cancelYoutubeImport: vi.fn(() => true),
+ attachImportSseClient: vi.fn(() => true),
+}));
+
+vi.mock('../services/trackSunoImport.js', () => ({
+ startSunoImport: vi.fn(async () => ({ jobId: 'suno-1' })),
+ cancelSunoImport: vi.fn(() => true),
+ attachSunoImportSseClient: vi.fn(() => true),
+}));
+
+vi.mock('../services/tracks/index.js', async () => ({
+ ...await import('../services/tracks/logic.js'),
+ getTrack: vi.fn(async (id) => ({ id })),
+}));
+
+vi.mock('../services/roundReferenceAudioImport.js', () => ({
+ startReferenceAudioImport: effects.startReferenceAudioImport,
+ cancelReferenceAudioImport: vi.fn(() => true),
+ attachReferenceAudioSseClient: vi.fn(() => true),
+}));
+
+vi.mock('../services/audioMidiTranscription.js', () => ({
+ startMidiTranscription: effects.startMidiTranscription,
+ cancelMidiTranscription: vi.fn(() => true),
+ attachMidiTranscriptionSseClient: vi.fn(() => true),
+ getActiveMidiTranscriptionJobId: vi.fn(() => null),
+ MUSCRIPTOR_MODELS: ['small', 'medium', 'large'],
+}));
+
+vi.mock('../services/musicVideo/projects.js', () => ({
+ getProject: vi.fn(async (id) => ({
+ id,
+ name: 'Example Video',
+ trackId: 'track-1',
+ uploadedAudioFilename: 'audio.wav',
+ lyricCues: [{ id: 'cue-1', text: 'Example lyrics' }],
+ })),
+ updateProject: vi.fn(async () => ({})),
+}));
+
+vi.mock('../services/musicVideo/projectAudio.js', () => ({
+ resolveProjectAudioPath: vi.fn(async () => '/fake/audio.wav'),
+ analyzeProjectSong: vi.fn(async () => ({})),
+}));
+
+vi.mock('../services/musicVideo/vocalSeparation.js', () => ({
+ startVocalSeparation: effects.startVocalSeparation,
+ cancelVocalSeparation: vi.fn(() => true),
+ attachVocalSeparationSseClient: vi.fn(() => true),
+}));
+
+vi.mock('../services/musicVideo/lyricAlignJob.js', () => ({
+ startLyricAlign: effects.startLyricAlign,
+ cancelLyricAlign: vi.fn(() => true),
+ attachLyricAlignSseClient: vi.fn(() => true),
+ getActiveLyricAlignJobId: vi.fn(() => null),
+}));
+
+vi.mock('../services/loraEffectProbe.js', () => ({
+ probeLoraEffect: effects.probeLoraEffect,
+}));
+
+vi.mock('../services/loras.js', () => ({
+ listLoras: vi.fn(async () => []),
+ assertSafeLoraFilename: vi.fn(),
+}));
+
+import { authGate, hostControlRouteGate } from '../services/authGate.js';
+import { isHostControlRoute } from '../lib/hostControlRoutes.js';
+import videoDownloadRoutes from './videoDownload.js';
+import tracksRoutes from './tracks.js';
+import roundsRoutes from './rounds.js';
+import musicVideoRoutes from './musicVideo.js';
+import lorasRoutes from './loras.js';
+
+const routes = [
+ ['/api/devtools/video-download', { url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' }, effects.startVideoDownload],
+ ['/api/tracks/import/youtube', { url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' }, effects.startYoutubeImport],
+ ['/api/rounds/reference-audio/import', { url: 'https://example.com/audio.mp3', roundId: '00000000-0000-4000-8000-000000000001', referenceId: 'ref-1' }, effects.startReferenceAudioImport],
+ ['/api/rounds/reference-audio/transcribe-midi', { filename: 'audio.wav' }, effects.startMidiTranscription],
+ ['/api/music-video/proj-1/transcribe-midi', {}, effects.startMidiTranscription],
+ ['/api/music-video/proj-1/vocal-stem/separate', {}, effects.startVocalSeparation],
+ ['/api/music-video/proj-1/lyrics/align', {}, effects.startLyricAlign],
+ ['/api/loras/test-lora.safetensors/effect', {}, effects.probeLoraEffect],
+];
+
+const appFor = (address = '192.0.2.10') => {
+ const app = express();
+ app.use((req, _res, next) => {
+ Object.defineProperty(req.socket, 'remoteAddress', { value: address });
+ next();
+ });
+ app.use(authGate, hostControlRouteGate, express.json());
+ app.use('/api/devtools/video-download', videoDownloadRoutes);
+ app.use('/api/tracks', tracksRoutes);
+ app.use('/api/rounds', roundsRoutes);
+ app.use('/api/music-video', musicVideoRoutes);
+ app.use('/api/loras', lorasRoutes);
+ app.use(errorMiddleware);
+ return app;
+};
+
+const post = (app, path, body = {}, headers = {}) => {
+ const pending = request(app).post(path);
+ for (const [k, v] of Object.entries(headers)) pending.set(k, v);
+ return pending.send(body);
+};
+
+const expectNoEffects = () => {
+ for (const [, , effect] of routes) {
+ expect(effect).not.toHaveBeenCalled();
+ }
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ state.enabled = false;
+});
+
+describe('media process execution operator authority', () => {
+ it('lists every media process execution endpoint as a host-control route', () => {
+ for (const [path] of routes) {
+ expect(isHostControlRoute('POST', path), path).toBe(true);
+ }
+ });
+
+ it('refuses remote password-free callers before spawning any host processes', async () => {
+ const app = appFor();
+ for (const [path, body] of routes) {
+ const res = await post(app, path, body);
+ expect([res.status, res.body.code], path).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);
+ expect(res.headers['content-type']).toMatch(/^application\/json/);
+ }
+ expectNoEffects();
+ });
+
+ it('rejects anonymous (401) and legacy Basic (403) callers on a password-enabled install', async () => {
+ state.enabled = true;
+ const basic = { Authorization: 'Basic ' + Buffer.from(':example-password').toString('base64') };
+ const app = appFor();
+ for (const [path, body] of routes) {
+ const anon = await post(app, path, body);
+ expect([anon.status, anon.body.code], path).toEqual([401, 'AUTH_REQUIRED']);
+ const legacy = await post(app, path, body, basic);
+ expect([legacy.status, legacy.body.code], path).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);
+ }
+ expectNoEffects();
+ });
+
+ it('admits local callers when auth is off, and operator sessions when auth is on', async () => {
+ const local = appFor('127.0.0.1');
+ const [path, body, effect] = routes[0];
+ const resLocal = await post(local, path, body);
+ expect(resLocal.status).toBe(202);
+ expect(effect).toHaveBeenCalledTimes(1);
+
+ state.enabled = true;
+ const operator = appFor();
+ const resOp = await post(operator, path, body, { Authorization: 'Bearer example-session' });
+ expect(resOp.status).toBe(202);
+ expect(effect).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps reads and status endpoints open to remote callers', async () => {
+ const app = appFor();
+ const downloads = await request(app).get('/api/devtools/video-download/downloads');
+ expect(downloads.status).toBe(200);
+
+ const ytdlp = await request(app).get('/api/devtools/video-download/yt-dlp');
+ expect(ytdlp.status).toBe(200);
+
+ const loras = await request(app).get('/api/loras');
+ expect(loras.status).toBe(200);
+ });
+});