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: prevent trailing slashes bypassing host-control authorization (#8950)
[._.]/ Adam Eivy8cf82dd7d056
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex 275ffc5482..b7660d17e6 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -355,7 +355,9 @@ const compileSegment = (segment) => {const compileRoute = (route) => {const [method, path] = route.split(' ');const body = path.split('/').slice(1).map(compileSegment).join('/');- return { route, method, pattern: new RegExp(`^/${body}/?$`, 'i') };+ // A mount can consume one slash before its root handler accepts another.+ // Match trailing runs conservatively without rewriting request identifiers.+ return { route, method, pattern: new RegExp(`^/${body}/*$`, 'i') };};const COMPILED_ROUTES = HOST_CONTROL_ROUTES.map(compileRoute);diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.jsindex ea3ebb60ad..f22569b47f 100644--- a/server/lib/hostControlRoutes.test.js+++ b/server/lib/hostControlRoutes.test.js@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';import { getApiRouteCatalog } from './apiRouteGraph.js';-import { HOST_CONTROL_ROUTES, hostControlBodyKeys, hostControlRouteFor, isHostControlRoute } from './hostControlRoutes.js';+import { HOST_CONTROL_ROUTES, hostControlBodyKeys, hostControlSettingsPathsIn, hostControlRouteFor, isHostControlRoute } from './hostControlRoutes.js';describe('HOST_CONTROL_ROUTES (#8716)', () => {it('names only mounted routes, so a rename cannot silently ungate one', () => {@@ -12,9 +12,19 @@ describe('HOST_CONTROL_ROUTES (#8716)', () => {expect(HOST_CONTROL_ROUTES.filter((route) => !reached.has(route))).toEqual([]);});- it('matches the spellings Express routes to the same handler, and nothing wider', () => {+ it('covers Express spellings conservatively while preserving route boundaries', () => {expect(isHostControlRoute('post', '/API/Apps/example-app/START/')).toBe(true);expect(isHostControlRoute('POST', '/api/git/status')).toBe(true);+ for (const suffix of ['//', '////']) {+ expect(hostControlRouteFor('post', '/API/Runs' + suffix)).toBe('POST /api/runs');+ expect(hostControlBodyKeys('put', '/API/Settings' + suffix, { harnesses: {} })).toEqual(['harnesses']);+ expect(hostControlSettingsPathsIn('PUT', '/api/settings' + suffix, {+ imageGen: { codex: { codexPath: '/example/codex' } },+ })).toEqual(['imageGen.codex.codexPath']);+ }+ expect(isHostControlRoute('POST', '/api/runs-example//')).toBe(false);+ expect(isHostControlRoute('POST', '/api//runs')).toBe(false);+expect(isHostControlRoute('PUT', '/api/apps/example-app/documents/docs/example.md')).toBe(true);// Read-only GETs and neighbouring paths stay open.expect(isHostControlRoute('GET', '/api/apps/example-app/start')).toBe(false);diff --git a/server/services/authGate.test.js b/server/services/authGate.test.jsindex 5cbe4910ff..d3227e6084 100644--- a/server/services/authGate.test.js+++ b/server/services/authGate.test.js@@ -673,6 +673,85 @@ describe('host-control authority', () => {});});+describe('mounted host-control trailing slashes (#8950)', () => {+ const buildApp = async (remoteAddress = '192.0.2.10') => {+ const { authGate, hostControlRouteGate, hostControlBodyGate } = await import('./authGate.js');+ const { createRunsRoutes } = await import('../lib/aiToolkit/routes/runs.js');+ const runner = {+ createRun: vi.fn().mockResolvedValue({ runId: 'example-run', provider: { type: 'cli' }, metadata: {} }),+ executeCliRun: vi.fn(),+ listRuns: vi.fn().mockResolvedValue([]),+ };+ const persist = vi.fn();+ const app = express();+ app.use((req, res, next) => {+ Object.defineProperty(req.socket, 'remoteAddress', { value: remoteAddress, configurable: true });+ next();+ });+ app.use(authGate);+ app.use(hostControlRouteGate);+ app.use(express.json());+ app.use(hostControlBodyGate);+ app.use('/api/runs', createRunsRoutes(runner));+ const settings = express.Router();+ settings.put('/', (req, res) => {+ persist(req.body);+ res.json({ saved: true });+ });+ app.use('/api/settings', settings);+ return { app, runner, persist };+ };+ const runBody = { providerId: 'example-cli', prompt: 'Example prompt' };+ const protectedBodies = [+ { harnesses: {} },+ { imageGen: { codex: { codexPath: '/example/codex' } } },+ ];++ it('denies remote password-free dispatch and protected writes before either sink', async () => {+ const { app, runner, persist } = await buildApp();+ for (const suffix of ['', '/', '//']) {+ const run = await request(app).post('/api/runs' + suffix).send(runBody);+ expect(run.status).toBe(403);+ expect(run.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ for (const body of protectedBodies) {+ const write = await request(app).put('/api/settings' + suffix).send(body);+ expect(write.status).toBe(403);+ expect(write.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ }+ }+ expect(runner.createRun).not.toHaveBeenCalled();+ expect(runner.executeCliRun).not.toHaveBeenCalled();+ expect(persist).not.toHaveBeenCalled();+ expect((await request(app).get('/api/runs//')).status).toBe(200);+ expect((await request(app).put('/api/settings//').send({ location: {} })).status).toBe(200);+ expect(persist).toHaveBeenCalledExactlyOnceWith({ location: {} });+ });++ it.each(['local', 'session', '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')}`];+ }+ const { app, runner, persist } = await buildApp(authority === 'session' ? '192.0.2.10' : '127.0.0.1');+ const allowed = authority !== 'basic';+ for (const suffix of ['', '/', '//']) {+ const run = await request(app).post('/api/runs' + suffix).set(...header).send(runBody);+ expect(run.status).toBe(allowed ? 202 : 403);+ for (const body of protectedBodies) {+ const write = await request(app).put('/api/settings' + suffix).set(...header).send(body);+ expect(write.status).toBe(allowed ? 200 : 403);+ if (!allowed) expect(write.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ }+ if (!allowed) expect(run.body.code).toBe('HOST_CONTROL_FORBIDDEN');+ }+ expect(runner.executeCliRun).toHaveBeenCalledTimes(allowed ? 3 : 0);+ expect(persist).toHaveBeenCalledTimes(allowed ? 6 : 0);+ });+});+describe('paired peer credential (#8356)', () => {const PAIR_SECRET = 'example-pair-secret-0123456789-abcdef';const PEER_ID = 'peer-example-instance';