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 Autofixer repair policy
atomantic52a9e72ce719
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex ba28b2063b..f8e65a092d 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -899,7 +899,7 @@ export const HOST_CONTROL_ROUTES = Object.freeze([/*** `PUT /api/settings` slices that set what runs or the guardrails around it:- * harness enablement and wrapper CLIs, the Code Animation worker tools, the+ * Autofixer repair policy, harness enablement and wrapper CLIs, the Code Animation worker tools, the* code-review chain, the untrusted content screen in front of agent work,* scheduled self-update, scheduled series autopilots, and backup destination/* recovery policy, and whole-root voice policy replacement. The store is@@ -907,6 +907,9 @@ export const HOST_CONTROL_ROUTES = Object.freeze([*/export const HOST_CONTROL_SETTINGS_SLICES = Object.freeze(['autoUpdate',+ // Deferred repair policy: verifyCommand runs a shell and autoPromote can+ // apply the repair to the live checkout. Provider pins also select its agent.+ 'autofixer',// Destination, schedule, exclusions and retention control private copies// and recovery durability, including writes consumed later by the scheduler.'backup',diff --git a/server/routes/settings.js b/server/routes/settings.jsindex fe3912fd78..459802e34f 100644--- a/server/routes/settings.js+++ b/server/routes/settings.js@@ -2,6 +2,7 @@ import { PRIVATE_CREDENTIALS, putCredential } from '../services/privateKeyStore.import { Router } from 'express';import { z } from 'zod';import { getSettings, updateSettingsWith } from '../services/settings.js';+import { assertHostControl } from '../services/authGate.js';import { getAiAssignments, updateAiAssignment } from '../services/aiAssignments.js';import { saveSubscriptionCosts } from '../services/subscriptionCosts.js';import { savePlanTiers } from '../services/subscriptions.js';@@ -373,6 +374,9 @@ router.put('/features/groups/:groupId', asyncHandler(async (req, res) => {// PUT /api/settings/ai-assignments/:idrouter.put('/ai-assignments/:id', asyncHandler(async (req, res) => {+ // This facade replaces the Autofixer slice, including its verification policy.+ // Check the decoded identifier so encoded route params cannot bypass the gate.+ if (req.params.id === 'settings.autofixer') assertHostControl(req);const payload = validateRequest(aiAssignmentUpdateSchema, req.body || {});res.json(await updateAiAssignment(req.params.id, payload));}));diff --git a/server/routes/settings.test.js b/server/routes/settings.test.jsindex 527dcb37ad..bd07d81fe5 100644--- a/server/routes/settings.test.js+++ b/server/routes/settings.test.js@@ -134,6 +134,7 @@ import { reconcileBeeperIngestion } from '../services/beeperArming.js';import { reconcileItermBridge } from '../services/itermBridge.js';import { restartBeeperScheduler, isBeeperSchedulerRegistered } from '../services/beeperScheduler.js';import { updateSettingsWith } from '../services/settings.js';+import { updateAiAssignment } from '../services/aiAssignments.js';import { hasConfiguredInstances as hasConfiguredDatadogInstances } from '../services/datadog.js';import { hasConfiguredInstances as hasConfiguredJiraInstances } from '../services/jira.js';import { assertEidoverseInstalled, installEidoverse, setEidoverseWorldsOrigin } from '../services/eidoverse.js';@@ -1694,3 +1695,55 @@ describe('generic voice settings operator authority', () => {expect(store.voice).toEqual(original);});});+++// A remote policy write must not become a trusted shell command on a later+// Autofixer repair, or turn a staged patch into an automatic live promotion.+describe('autofixer settings operator authority', () => {+ const original = { providerId: 'example-cli', model: 'example-model', verifyCommand: 'npm test', autoPromote: false };+ beforeEach(() => { store = { autofixer: { ...original } }; vi.clearAllMocks(); });++ it('refuses command, promotion, provider and clearing writes before persistence', async () => {+ for (const autofixer of [+ { verifyCommand: 'echo example-verification' },+ { autoPromote: true },+ { providerId: 'another-cli' },+ { verifyCommand: '' },+ {},+ null,+ ]) {+ const response = await request(guardedSettingsApp('remote')).put('/api/settings').send({ autofixer });+ expect([response.status, response.body.code]).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ expect(store.autofixer).toEqual(original);+ }+ expect(updateSettingsWith).not.toHaveBeenCalled();+ });++ it.each(['local', 'session'])('preserves %s repair policy updates and explicit clears', async authority => {+ const app = guardedSettingsApp(authority);+ const response = await request(app).put('/api/settings').send({ autofixer: { verifyCommand: 'echo example-verification', autoPromote: true } });+ expect(response.status).toBe(200);+ expect(store.autofixer).toEqual({ ...original, verifyCommand: 'echo example-verification', autoPromote: true });+ expect((await request(app).put('/api/settings').send({ autofixer: { verifyCommand: '', autoPromote: false } })).status).toBe(200);+ expect(store.autofixer).toEqual({ ...original, verifyCommand: '' });+ });++ it('gates the assignment facade that can replace the same repair policy', async () => {+ const body = { providerId: 'example-cli', model: 'another-model' };+ for (const id of ['settings.autofixer', 'settings%2Eautofixer']) {+ const denied = await request(guardedSettingsApp('remote')).put(`/api/settings/ai-assignments/${id}`).send(body);+ expect([denied.status, denied.body.code]).toEqual([403, 'HOST_CONTROL_FORBIDDEN']);+ }+ expect(updateAiAssignment).not.toHaveBeenCalled();+ for (const authority of ['local', 'session']) {+ expect((await request(guardedSettingsApp(authority)).put('/api/settings/ai-assignments/settings.autofixer').send(body)).status).toBe(200);+ }+ expect(updateAiAssignment).toHaveBeenCalledTimes(2);+ expect(updateAiAssignment).toHaveBeenLastCalledWith('settings.autofixer', body);+ });++ it('keeps unrelated remote settings saves open without changing deferred repair policy', async () => {+ expect((await request(guardedSettingsApp('remote')).put('/api/settings').send({ theme: 'dark' })).status).toBe(200);+ expect(store.autofixer).toEqual(original);+ });+});diff --git a/server/services/authGate.test.js b/server/services/authGate.test.jsindex b38f61ae14..9f5a70e939 100644--- a/server/services/authGate.test.js+++ b/server/services/authGate.test.js@@ -787,6 +787,7 @@ describe('mounted host-control trailing slashes (#8950)', () => {const runBody = { providerId: 'example-cli', prompt: 'Example prompt' };const protectedBodies = [{ harnesses: {} },+ { autofixer: { verifyCommand: 'npm test', autoPromote: true } },{ imageGen: { codex: { codexPath: '/example/codex' } } },// A PATCH-shaped extra field must not change how a legacy PUT is gated.{ slicePath: 'pipeline', partial: {}, imageGen: { local: { pythonPath: '/example/python3' } } },@@ -862,13 +863,19 @@ describe('mounted host-control trailing slashes (#8950)', () => {expect(local.persist).toHaveBeenCalledTimes(2);});- it.each(['local', 'session', 'basic'])('preserves %s authority through mounted root handlers', async (authority) => {+ it.each(['local', 'session', 'agent', 'basic'])('preserves %s authority through mounted root handlers', async (authority) => {let header = ['X-Example', 'local'];if (authority !== 'local') {const { token } = await (await import('./auth.js')).setPassword({ newPassword: 'example-password' });- header = authority === 'session'- ? ['Cookie', `portos_auth=${token}`]- : ['Authorization', `Basic ${Buffer.from(':example-password').toString('base64')}`];+ if (authority === 'agent') {+ const { resolveAgentApiEnv } = await import('./agentApiAuth.js');+ const { PORTOS_API_TOKEN } = await resolveAgentApiEnv();+ header = ['Authorization', `Bearer ${PORTOS_API_TOKEN}`];+ } else {+ header = authority === 'session'+ ? ['Cookie', `portos_auth=${token}`]+ : ['Authorization', `Basic ${Buffer.from(':example-password').toString('base64')}`];+ }}const { app, runner, persist } = await buildApp(authority === 'session' ? '192.0.2.10' : '127.0.0.1');const allowed = authority !== 'basic';@@ -883,7 +890,7 @@ describe('mounted host-control trailing slashes (#8950)', () => {if (!allowed) expect(run.body.code).toBe('HOST_CONTROL_FORBIDDEN');}expect(runner.executeCliRun).toHaveBeenCalledTimes(allowed ? 3 : 0);- expect(persist).toHaveBeenCalledTimes(allowed ? 9 : 0);+ expect(persist).toHaveBeenCalledTimes(allowed ? protectedBodies.length * 3 : 0);});});