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: require operator authority for Music Video ffmpeg render dispatch (#12514)
[._.]/ Adam Eivy394ae05571a2
diff --git a/docs/API.md b/docs/API.mdindex b4eaa295e8..ea61b7a9b4 100644--- a/docs/API.md+++ b/docs/API.md@@ -606,6 +606,11 @@ leaves finished ones alone. Agents outside PortOS call these with `node scripts/| GET | `/music-video/:id/publish/promotion-plan` | A music video's open promotion steps || POST | `/music-video/:id/publish/promotion-plan` | Plan its promotion with one provider call `{ goal?, audience?, days?, providerId?, model? }` and schedule the steps || POST | `/music-video/:id/publish/:target/preview` | What Fill draft would post for one platform (same body as prepare) → `{ ready, parts }` or `{ ready: false, problem }` |+| POST | `/music-video/:id/render` | Start the final render (ffmpeg on the host). Host-control gated: a remote password-free caller, a peer credential or Basic is refused; local connections, operator sessions and `PORTOS_API_TOKEN` agents are allowed. Status, SSE events and cancel stay open |+| POST | `/music-video/:id/shots/:sceneId/render` | Render one shot segment (ffmpeg). Host-control gated as the final render |+| POST | `/music-video/:id/shot-renders/preview` | Concat the rendered shots with the song into a preview (ffmpeg). Host-control gated as the final render |+| POST | `/music-video/:id/excerpt` | Start an excerpt encode (ffmpeg). Host-control gated as the final render |+| POST | `/music-video/:id/publish-kit/build` | Build platform encodes and thumbnails (ffmpeg). Host-control gated as the final render || POST | `/music-video/publish/cover-fonts` | Upload a cover lettering font. Host-control gated: the file is installed into a host-wide font folder (macOS `Library/Fonts/PortOS`), so a remote caller on a password-free install is refused; local connections, operator sessions and `PORTOS_API_TOKEN` agents are allowed. Listing and serving (`GET`) and delete stay open |### Notificationsdiff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex 28ca48585d..46cbee1a51 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -630,6 +630,13 @@ export const HOST_CONTROL_ROUTES = Object.freeze(['POST /api/video-gen/history/:id/trim-start',// Timeline render spawns ffmpeg/ffprobe on the host for segments and audio (#11432).'POST /api/video-timeline/projects/:id/render',+ // Music Video ffmpeg renders: final render, per-shot segments, shot preview+ // concat with the song, excerpt encode, and platform encodes/thumbnails (#12514).+ 'POST /api/music-video/:id/render',+ 'POST /api/music-video/:id/shots/:sceneId/render',+ 'POST /api/music-video/:id/shot-renders/preview',+ 'POST /api/music-video/:id/excerpt',+ 'POST /api/music-video/:id/publish-kit/build','POST /api/sprites/:id/reference/generate',// Fork creates a record and immediately queues reference generation too.'POST /api/sprites/:id/fork',diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.jsindex 7565b3e880..fa9da9f6bb 100644--- a/server/lib/hostControlRoutes.test.js+++ b/server/lib/hostControlRoutes.test.js@@ -602,7 +602,7 @@ describe('Music Video cover font install policy (#12493)', () => {});describe('Music Video agent workflow policy (#9869)', () => {- it('gates mounted agent workflows and keeps record, cancellation and contained rendering contracts', () => {+ it('gates mounted agent workflows and keeps record and cancellation contracts open while gating ffmpeg renders (#12514)', () => {const protectedRoutes = ['POST /api/music-video/:id/plan','POST /api/music-video/:id/treatment/compile',@@ -621,6 +621,11 @@ describe('Music Video agent workflow policy (#9869)', () => {'POST /api/music-video/:id/production-runs/:runId/resume','POST /api/music-video/:id/auto-reviews','POST /api/music-video/:id/auto-reviews/:runId/resume',+ 'POST /api/music-video/:id/render',+ 'POST /api/music-video/:id/shots/:sceneId/render',+ 'POST /api/music-video/:id/shot-renders/preview',+ 'POST /api/music-video/:id/excerpt',+ 'POST /api/music-video/:id/publish-kit/build',];const mounted = new Set(getApiRouteCatalog().routes.map(({ method, path }) => method + ' ' + path));for (const route of protectedRoutes) {@@ -637,8 +642,6 @@ describe('Music Video agent workflow policy (#9869)', () => {'POST /api/music-video/:id/auto-reviews/:runId/cancel','POST /api/music-video/:id/composition/document/directory','GET /api/music-video/:id/composition/document',- 'POST /api/music-video/:id/render',- 'POST /api/music-video/:id/publish-kit/build','POST /api/music-video/:id/publish/:target/prepare',]) {const [method, path] = route.split(' ');diff --git a/server/routes/hostControlMusicVideoRender.test.js b/server/routes/hostControlMusicVideoRender.test.jsnew file mode 100644index 0000000000..1f279dfa55--- /dev/null+++ b/server/routes/hostControlMusicVideoRender.test.js@@ -0,0 +1,125 @@+import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';+import express from 'express';+import { request } from '../lib/testHelper.js';+import { errorMiddleware } from '../lib/errorHandler.js';+import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';++vi.mock('../lib/fileUtils.js', async (importOriginal) =>+ makePathsProxy(await importOriginal(), { dataRoot: () => lazyTempDataRoot('portos-mv-render-') }));+afterAll(cleanupTempDataRoots);++// ffmpeg dispatch routes of the Music Video family (#12514). Real router behind+// the real host-control gate; each ffmpeg sink is a spy so an unauthorized+// caller that reaches it is visible.+const state = vi.hoisted(() => ({ enabled: false }));+const sink = vi.hoisted(() => ({+ renderMusicVideo: vi.fn(async () => ({ jobId: 'render-example' })),+ startShotRender: vi.fn(async () => ({ jobId: 'shot-example' })),+ buildRenderPreview: vi.fn(async () => ({ path: 'preview-example.mp4' })),+ startExcerptRender: vi.fn(async () => ({ jobId: 'excerpt-example' })),+ startPublishKitBuild: vi.fn(async () => ({ jobId: 'kit-example' })),+}));++vi.mock('../services/auth.js', async (importOriginal) => ({+ ...await importOriginal(),+ 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: { on: vi.fn(), off: vi.fn(), emit: vi.fn() },+ getSettings: vi.fn(async () => ({})),+ updateSettingsWith: vi.fn(async (mutate) => mutate({})),+}));+vi.mock('../services/musicVideo/render.js', async (importOriginal) => ({+ ...await importOriginal(),+ renderMusicVideo: sink.renderMusicVideo,+}));+vi.mock('../services/musicVideo/shotSegments.js', async (importOriginal) => ({+ ...await importOriginal(),+ startShotRender: sink.startShotRender,+ buildRenderPreview: sink.buildRenderPreview,+}));+vi.mock('../services/musicVideo/excerptRender.js', async (importOriginal) => ({+ ...await importOriginal(),+ startExcerptRender: sink.startExcerptRender,+}));+vi.mock('../services/musicVideo/publishKit.js', async (importOriginal) => ({+ ...await importOriginal(),+ startPublishKitBuild: sink.startPublishKitBuild,+}));++import { authGate, hostControlBodyGate, hostControlRouteGate } from '../services/authGate.js';+import { DEV_PROXY_CLIENT_ADDRESS_HEADER } from '../../lib/portosAuthCore.js';+import musicVideoRoutes from './musicVideo.js';++const PROJECT = '/api/music-video/example-project';+const operations = [+ [`${PROJECT}/render`, {}, sink.renderMusicVideo],+ [`${PROJECT}/shots/example-scene/render`, {}, sink.startShotRender],+ [`${PROJECT}/shot-renders/preview`, {}, sink.buildRenderPreview],+ [`${PROJECT}/excerpt`, { startSec: 0, endSec: 5 }, sink.startExcerptRender],+ [`${PROJECT}/publish-kit/build`, {}, sink.startPublishKitBuild],+];+const sinks = operations.map(([, , service]) => service);++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(), hostControlBodyGate);+ app.use('/api/music-video', musicVideoRoutes);+ app.use(errorMiddleware);+ return app;+};+const post = (app, path, body, headers = {}) => {+ const pending = request(app).post(path);+ for (const [name, value] of Object.entries(headers)) pending.set(name, value);+ return pending.send(body);+};++beforeEach(() => {+ vi.clearAllMocks();+ state.enabled = false;+});++describe('Music Video ffmpeg render dispatch host control (#12514)', () => {+ it('refuses a remote password-free caller, including spoofed-proxy variants, before any ffmpeg dispatch', async () => {+ for (const [path, body] of operations) {+ for (const [address, headers] of [+ ['192.0.2.10', {}],+ ['127.0.0.1', { [DEV_PROXY_CLIENT_ADDRESS_HEADER]: '192.0.2.10' }],+ ]) {+ const response = await post(appFor(address), path, body, headers);+ expect([response.status, response.body.code], path).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ }+ }+ for (const service of sinks) expect(service).not.toHaveBeenCalled();+ });++ it('refuses a scoped peer credential or legacy Basic password even when authenticated', async () => {+ state.enabled = true;+ for (const [path, body] of operations) {+ const response = await post(appFor(), path, body, { Authorization: 'Basic ' + Buffer.from(':example-password').toString('base64') });+ expect([response.status, response.body.code], path).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ }+ for (const service of sinks) expect(service).not.toHaveBeenCalled();+ });++ it('still dispatches for a local connection and for an operator session with a password set', async () => {+ for (const [enabled, address, headers] of [+ [false, '127.0.0.1', {}],+ [true, '192.0.2.10', { Authorization: 'Bearer example-session' }],+ ]) {+ state.enabled = enabled;+ for (const [path, body, service] of operations) {+ const response = await post(appFor(address), path, body, headers);+ expect(response.status, `${path}: ${JSON.stringify(response.body)}`).not.toBe(403);+ expect(service, path).toHaveBeenCalled();+ service.mockClear();+ }+ }+ });+});