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

security: gate database admin routes behind host-control authority (#8897)

[._.]/ Adam Eivybf81b9b08685
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.js
index 28143907e4..87675c3ff3 100644
--- a/server/lib/hostControlRoutes.js
+++ b/server/lib/hostControlRoutes.js
@@ -80,6 +80,16 @@ export const HOST_CONTROL_ROUTES = Object.freeze([
'POST /api/database/maintenance/cutover',
'POST /api/database/maintenance/recover',
+ // Database admin routes: lifecycle, data integrity, and migration (#8897).
+ 'POST /api/database/start',
+ 'POST /api/database/stop',
+ 'POST /api/database/destroy',
+ 'POST /api/database/setup-native',
+ 'POST /api/database/export',
+ 'POST /api/database/sync',
+ 'POST /api/database/fix',
+ 'POST /api/database/switch',
+
// Setting a password mints an operator session: bootstrap must be local,
// and rotation must already hold operator authority (#8771).
'POST /api/auth/password',
diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.js
index eeeb712d4c..8130ca86f6 100644
--- a/server/lib/hostControlRoutes.test.js
+++ b/server/lib/hostControlRoutes.test.js
@@ -60,3 +60,21 @@ describe('browser/runtime mutation inventory (#8798)', () => {
expect([...new Set(open)].sort()).toEqual([...dataOrInference].sort());
});
});
+
+// Database mutation inventory (#8897): every /api/database/* mutation must be gated
+// as host control or explicitly reviewed as data-only. New mutations fail closed.
+describe('database mutation inventory (#8897)', () => {
+ const reviewedOpen = [
+ // POST /maintenance/preflight is advisory only — validates preconditions without side effects.
+ 'POST /api/database/maintenance/preflight',
+ ];
+
+ it('classifies every mounted mutation and keeps reviewed data-only operations open', () => {
+ const mutations = getApiRouteCatalog().routes.filter(({ method, path }) =>
+ /^(POST|PUT|PATCH|DELETE)$/.test(method)
+ && /^\/api\/database(\/|$)/.test(path));
+ const open = mutations.filter(({ method, path }) => !isHostControlRoute(method, path))
+ .map(({ method, path }) => `${method} ${path}`);
+ expect([...new Set(open)].sort()).toEqual([...reviewedOpen].sort());
+ });
+});
diff --git a/server/routes/database.test.js b/server/routes/database.test.js
index cdfaeeb107..875e088a88 100644
--- a/server/routes/database.test.js
+++ b/server/routes/database.test.js
@@ -768,3 +768,49 @@ describe('POST /api/database/sync endpoint safety', () => {
expect(res.status).toBe(200);
});
});
+
+// Host-control gating (#8897): database admin routes require operator authority.
+describe('database admin routes host-control gating', () => {
+ it.each([
+ ['start', { backend: 'docker' }],
+ ['stop', { backend: 'native' }],
+ ['destroy', { backend: 'docker' }],
+ ['setup-native', {}],
+ ['export', {}],
+ ['sync', {}],
+ ['fix', {}],
+ ['switch', { target: 'docker', migrate: false }],
+ ])('requires host-control authority for POST /api/database/%s', async (route, body) => {
+ const gated = express();
+ gated.use((req, _res, next) => {
+ req.portosAuthContext = { enabled: true, authenticated: false };
+ next();
+ });
+ const { hostControlRouteGate } = await import('../services/authGate.js');
+ gated.use(hostControlRouteGate);
+ gated.use(express.json());
+ gated.use('/api/database', databaseRoutes);
+ const res = await request(gated).post(`/api/database/${route}`).send(body);
+ expect(res.status).toBe(403);
+ expect(res.body.code).toBe('HOST_CONTROL_FORBIDDEN');
+ expect(execFile).not.toHaveBeenCalled();
+ expect(spawn).not.toHaveBeenCalled();
+ expect(query).not.toHaveBeenCalled();
+ });
+
+ it('allows preflight without host-control authority (advisory only)', async () => {
+ const gated = express();
+ gated.use((req, _res, next) => {
+ req.portosAuthContext = { enabled: true, authenticated: false };
+ next();
+ });
+ const { hostControlRouteGate } = await import('../services/authGate.js');
+ gated.use(hostControlRouteGate);
+ gated.use(express.json());
+ gated.use('/api/database', databaseRoutes);
+ const res = await request(gated).post('/api/database/maintenance/preflight').send({ source: 'native', target: 'docker' });
+ // preflight is read-only advisory, but returns 400 for this test input
+ // (no actual system idle) rather than 403.
+ expect(res.status).not.toBe(403);
+ });
+});