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 to install motion skills (#9439)
[._.]/ Adam Eivya00d668e5bb6
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex e1c4bed041..8269ecaff2 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -277,6 +277,9 @@ export const HOST_CONTROL_ROUTES = Object.freeze([// Runs the configured local or provider reviewer on a caller-supplied diff.'POST /api/code-review/local',+ // Motion toolkit: executes the downloaded installer and writes agent skills user-wide.+ 'POST /api/html-composition/toolkit/skills/install',+// Code Animation contained execution (#9388): choosing the installed tool a// worker runs, and the containment check that spawns sandboxed processes.'PUT /api/code-animation/execution/tools',diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.jsindex 6514ef174b..9aa87bac4a 100644--- a/server/lib/hostControlRoutes.test.js+++ b/server/lib/hostControlRoutes.test.js@@ -14,6 +14,9 @@ describe('HOST_CONTROL_ROUTES (#8716)', () => {it('covers Express spellings conservatively while preserving route boundaries', () => {expect(isHostControlRoute('post', '/API/Apps/example-app/START/')).toBe(true);+ expect(hostControlRouteFor('post', '/API/HTML-COMPOSITION/TOOLKIT/SKILLS/INSTALL/')).toBe('POST /api/html-composition/toolkit/skills/install');+ expect(isHostControlRoute('GET', '/api/html-composition/toolkit')).toBe(false);+ expect(isHostControlRoute('POST', '/api/html-composition/render')).toBe(false);expect(isHostControlRoute('POST', '/api/git/status')).toBe(true);for (const suffix of ['//', '////']) {expect(hostControlRouteFor('post', '/API/Runs' + suffix)).toBe('POST /api/runs');diff --git a/server/routes/htmlComposition.test.js b/server/routes/htmlComposition.test.jsindex 7ceb4b4319..d43ea6e664 100644--- a/server/routes/htmlComposition.test.js+++ b/server/routes/htmlComposition.test.js@@ -1,4 +1,4 @@-import { describe, it, expect, vi } from 'vitest';+import { beforeEach, describe, it, expect, vi } from 'vitest';import express from 'express';import { request } from '../lib/testHelper.js';import { errorMiddleware } from '../lib/errorHandler.js';@@ -6,20 +6,39 @@ import { enqueueJob } from '../services/mediaJobQueue/index.js';import { resolveMusicTrackPath } from '../services/pipeline/audioMux.js';import { getBeatGrid } from '../lib/beatGrid.js';import router from './htmlComposition.js';+import { authGate, hostControlRouteGate } from '../services/authGate.js';+import { execFile } from '../lib/childProcess.js';+import { derivePeerAuthToken } from '../lib/peerHttpClient.js';+import { DEV_PROXY_CLIENT_ADDRESS_HEADER } from '../../lib/portosAuthCore.js';++const authState = vi.hoisted(() => ({ enabled: false }));+vi.mock('../services/auth.js', () => ({+ isAuthEnabled: async () => authState.enabled,+ verifyPassword: async password => password === 'example-password',+ verifyRequestSession: async req => req.headers.authorization === 'Bearer example-operator-session',+}));+vi.mock('../services/settings.js', async () => ({+ getSettings: async () => ({}),+ settingsEvents: new (await import('node:events')).EventEmitter(),+}));+vi.mock('../services/instanceIdentity.js', () => ({+ loadData: async () => ({ peers: [{ id: 'example-peer', instanceId: 'example-instance', enabled: true, syncSecret: 'example-pair-secret-0123456789-abcdef' }] }),+}));+vi.mock('../lib/ffmpeg.js', () => ({ findFfmpeg: async () => '/example/ffmpeg' }));vi.mock('../services/mediaJobQueue/index.js', () => ({enqueueJob: vi.fn(async () => ({ jobId: 'example-job', status: 'queued' })),attachSseClient: vi.fn(() => false), cancelJob: vi.fn(),}));vi.mock('../services/pipeline/audioMux.js', () => ({ resolveMusicTrackPath: vi.fn(async () => null) }));-const skillState = vi.hoisted(() => ({ installed: false }));+const skillState = vi.hoisted(() => ({ installed: false, existingPack: null }));vi.mock('../lib/childProcess.js', async importOriginal => ({...(await importOriginal()),execFile: vi.fn((command, args, options, callback) => { skillState.installed = true; callback(null); }),}));vi.mock('../lib/motionSkills.js', async importOriginal => {const actual = await importOriginal();- return { ...actual, detectMotionSkills: () => actual.MOTION_SKILL_PACKS.map(pack => ({ id: pack.id, label: pack.label, skills: [...pack.skills], found: skillState.installed ? [...pack.skills] : [], installed: skillState.installed })) };+ return { ...actual, detectMotionSkills: () => actual.MOTION_SKILL_PACKS.map(pack => ({ id: pack.id, label: pack.label, skills: [...pack.skills], found: skillState.installed || pack.id === skillState.existingPack ? [...pack.skills] : [], installed: skillState.installed || pack.id === skillState.existingPack })) };});vi.mock('../lib/beatGrid.js', () => ({ getBeatGrid: vi.fn(async () => null) }));@@ -88,13 +107,78 @@ describe('GET /api/html-composition/beats (#8958)', () => {});});-describe('motion skills install', () => {- it('installs each missing skill pack through the skills CLI and returns the refreshed status', async () => {- const { execFile } = await import('../lib/childProcess.js');- const response = await request(app).post('/api/html-composition/toolkit/skills/install');+describe('motion skills install authority (#9439)', () => {+ const installPath = '/api/html-composition/toolkit/skills/install';+ const buildApp = (remoteAddress = '192.0.2.10') => {+ const gatedApp = express();+ gatedApp.use((req, res, next) => {+ Object.defineProperty(req.socket, 'remoteAddress', { value: remoteAddress, configurable: true });+ next();+ });+ gatedApp.use(authGate);+ gatedApp.use(hostControlRouteGate);+ gatedApp.use(express.json());+ gatedApp.use('/api/html-composition', router);+ gatedApp.use(errorMiddleware);+ return gatedApp;+ };++ beforeEach(() => {+ authState.enabled = false;+ skillState.installed = false;+ skillState.existingPack = null;+ execFile.mockClear();+ });++ it.each([+ ['192.0.2.10', '127.0.0.1'],+ ['127.0.0.1', '192.0.2.10'],+ ])('refuses a remote caller through socket %s and proxy marker %s before installing', async (remoteAddress, proxyAddress) => {+ const response = await request(buildApp(remoteAddress)).post('/API/HTML-COMPOSITION/TOOLKIT/SKILLS/INSTALL/')+ .set('X-Forwarded-For', '127.0.0.1')+ .set(DEV_PROXY_CLIENT_ADDRESS_HEADER, proxyAddress);+ expect(response.status).toBe(403);+ expect(response.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ expect(execFile).not.toHaveBeenCalled();+ expect(skillState.installed).toBe(false);+ });++ it('refuses legacy Basic and scoped peer credentials when a password is set', async () => {+ authState.enabled = true;+ const basic = await request(buildApp()).post(installPath)+ .set('Authorization', `Basic ${Buffer.from(':example-password').toString('base64')}`);+ expect(basic.status).toBe(403);+ expect(basic.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ const peer = await request(buildApp()).post(installPath)+ .set('X-PortOS-Instance-Id', 'example-instance')+ .set('X-PortOS-Peer-Auth', derivePeerAuthToken('example-pair-secret-0123456789-abcdef', 'example-instance'));+ expect(peer.status).toBe(403);+ expect(peer.body.code).toBe('PEER_SCOPE_FORBIDDEN');+ expect(execFile).not.toHaveBeenCalled();+ expect(skillState.installed).toBe(false);+ });++ it.each(['loopback', 'operator-session'])('allows %s authority and installs only missing packs', async mode => {+ const { MOTION_SKILL_PACKS, skillInstallCommand } = await import('../lib/motionSkills.js');+ skillState.existingPack = MOTION_SKILL_PACKS[0].id;+ authState.enabled = mode === 'operator-session';+ const pending = request(buildApp(mode === 'loopback' ? '127.0.0.1' : '192.0.2.10')).post(installPath);+ if (authState.enabled) pending.set('Authorization', 'Bearer example-operator-session');+ const response = await pending;expect(response.status).toBe(200);- expect(execFile).toHaveBeenCalledTimes(3);- expect(execFile.mock.calls[0][0]).toBe('npx');+ expect(execFile).toHaveBeenCalledTimes(MOTION_SKILL_PACKS.length - 1);+ expect(execFile.mock.calls.map(([command, args]) => [command, args])).toEqual(MOTION_SKILL_PACKS.slice(1).map(skillInstallCommand));expect(response.body.skillPacks.every(pack => pack.installed)).toBe(true);+ execFile.mockClear();+ expect((await request(buildApp('127.0.0.1')).post(installPath)+ .set('Authorization', 'Bearer example-operator-session')).status).toBe(200);+ expect(execFile).not.toHaveBeenCalled();+ });++ it('keeps toolkit status and contained rendering available to a remote password-free caller', async () => {+ const gatedApp = buildApp();+ expect((await request(gatedApp).get('/api/html-composition/toolkit')).status).toBe(200);+ expect((await request(gatedApp).post('/api/html-composition/render').send({ directory: 'compositions/example' })).status).toBe(202);+ expect(execFile).not.toHaveBeenCalled();});});