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: deny ungranted execution before reading the database
[._.]/ Adam Eivy786c3a0544d8
diff --git a/server/routes/peerAdministration.test.js b/server/routes/peerAdministration.test.jsindex b8427d132e..6a650ce0d5 100644--- a/server/routes/peerAdministration.test.js+++ b/server/routes/peerAdministration.test.js@@ -19,6 +19,10 @@ vi.mock('../services/auth.js', () => ({verifyPassword: async () => true,}));vi.mock('../services/settings.js', () => ({ getSettings: async () => ({}), settingsEvents: new EventEmitter() }));+// Unit CI deliberately has no database; default-deny must not consult it.+vi.mock('../lib/db.js', async () => ({+ ...await vi.importActual('../lib/db.js'), query: vi.fn(async () => { throw new Error('Fixture database unavailable'); }),+}));vi.mock('../lib/peerHttpClient.js', async () => ({...await vi.importActual('../lib/peerHttpClient.js'), peerFetch: vi.fn(),}));@@ -32,6 +36,7 @@ const { authGate, hostControlRouteGate } = await import('../services/authGate.jsconst { default: receiver } = await import('./peerAdministration.js');const { default: peerAdminOperatorRoutes } = await import('./peerAdminOperator.js');const { errorMiddleware } = await import('../lib/errorHandler.js');+const { query } = await import('../lib/db.js');const { derivePeerAuthToken, peerFetch } = await import('../lib/peerHttpClient.js');// Fixture peers sign the wire envelope independently of the receiving service.const signPeerAdmin = (peer, purpose, payload) => createHmac('sha256', peer.syncSecret)@@ -96,8 +101,9 @@ describe('bounded administration through the real authority boundary', () => {await grant();const input = { protocolVersion: 1, requestId: randomUUID(), intent };const denied = await peerRequest('execution/preflight', input);- expect(denied.status).toBe(403);+ expect(denied.status, JSON.stringify(denied.body)).toBe(403);expect(denied.body.code).toBe('PEER_EXECUTION_GRANT_REQUIRED');+ expect(query).not.toHaveBeenCalled();expect((await request(app).post(`${ROOT}/execution/preflight`).send(input)).status).toBe(401);expect((await peerRequest('execution/dispatch', { ...input, command: 'fixture-injection' })).status).toBe(400);expect(execution.restart).not.toHaveBeenCalled();diff --git a/server/services/peerExecution.js b/server/services/peerExecution.jsindex e4168797ac..3a73bf9dbc 100644--- a/server/services/peerExecution.js+++ b/server/services/peerExecution.js@@ -45,9 +45,11 @@ export function createPeerExecutionReceiver({ ledger, grants, coordinator, adaptconst preflight = (req, input) => locked(async () => {for (const [key, value] of preflights) if (value.payload.expiresAt <= now()) preflights.delete(key);const pair = await caller(req);+ // Default-deny is independent of database availability. Do not read the+ // ledger or probe adapters until this exact pair has an execution grant.+ const { grant } = await grants.current(pair.peer.id, input.intent.action);if (await findRequest(pair, input.requestId)) fail('PEER_EXECUTION_CONSUMED', 'Use status for an already-consumed request.');if (preflights.size >= 128) fail('PEER_EXECUTION_PREFLIGHT_LIMIT', 'Too many outstanding execution preflights.');- const { grant } = await grants.current(pair.peer.id, input.intent.action);const evidence = await adapters.prepare(input.intent);const binding = { hostInstanceId: pair.self.instanceId, peerInstanceId: pair.peer.instanceId,requestId: input.requestId, grantId: grant.id, grantGeneration: grant.generation, scope: 'execution-v1',diff --git a/server/services/peerExecution.test.js b/server/services/peerExecution.test.jsindex 073f3d9c2e..fe464f2657 100644--- a/server/services/peerExecution.test.js+++ b/server/services/peerExecution.test.js@@ -106,6 +106,7 @@ describe('receiver execution public workflow with fixture-only side effects', ()const retired = await restarted.status('paired', { requestId, preflight: envelope });expect(retired.payload).toMatchObject({ state: 'failed', code: 'PEER_EXECUTION_NOT_ACCEPTED' });expect((await receiver.dispatch('paired', dispatch)).payload).toEqual(retired.payload);+ await grant();await expect(restarted.preflight('paired', { protocolVersion: 1, requestId, intent })).rejects.toMatchObject({ code: 'PEER_EXECUTION_CONSUMED' });await makeReceiver().recover();expect((await restarted.status('paired', { requestId })).payload).toEqual(retired.payload);