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

fix(security): keep the managed visitor broker loopback-only behind the dev proxy

Adam Eivyc45c7e89ff38
diff --git a/server/routes/managedVisitors.test.js b/server/routes/managedVisitors.test.js
index 0ae7591b3c..d036c968e9 100644
--- a/server/routes/managedVisitors.test.js
+++ b/server/routes/managedVisitors.test.js
@@ -6,6 +6,7 @@ import { tmpdir } from 'node:os';
import { EventEmitter } from 'node:events';
import { createManagedVisitorBroker, managedVisitorContract } from '../services/managedVisitorBroker.js';
import { request } from '../lib/testHelper.js';
+import { DEV_PROXY_CLIENT_ADDRESS_HEADER } from '../../lib/portosAuthCore.js';
const shared = vi.hoisted(() => ({ enabled: false, broker: null }));
vi.mock('../services/auth.js', () => ({ isAuthEnabled: async () => shared.enabled, extractToken: req => req.headers.authorization?.slice(7),
verifySession: async token => token === 'owner-session',
@@ -100,6 +101,11 @@ it('denies cross-origin provisioning and nonloopback broker callers even without
expect((await request(app).post(`/api/managed-visitor-admin/${appId}/credential`).set('Origin', 'https://unrelated.invalid').send(credentialInput)).status).toBe(403);
const { authenticateManagedVisitorRequest } = await vi.importActual('../services/managedVisitors.js');
await expect(authenticateManagedVisitorRequest({ socket: { remoteAddress: '192.0.2.1' }, headers: { authorization: authHeader() } }, shared.broker)).rejects.toThrow(/local/);
+ // A remote browser relayed by the Vite dev proxy arrives on a loopback socket.
+ const proxied = { socket: { remoteAddress: '127.0.0.1' }, headers: { authorization: authHeader(), [DEV_PROXY_CLIENT_ADDRESS_HEADER]: '192.0.2.1' } };
+ await expect(authenticateManagedVisitorRequest(proxied, shared.broker)).rejects.toThrow(/local/);
+ const localProxied = { socket: { remoteAddress: '127.0.0.1' }, headers: { authorization: authHeader(), [DEV_PROXY_CLIENT_ADDRESS_HEADER]: '::1' } };
+ expect((await authenticateManagedVisitorRequest(localProxied, shared.broker)).appId).toBe(appId);
});
it('revokes malformed/private host outputs instead of forwarding or retrying uncertain operations', async () => {
const auth = await shared.broker.authenticate(credentials.credential), visit = await shared.broker.admit(auth, admission);
diff --git a/server/services/managedVisitors.js b/server/services/managedVisitors.js
index 7289ae9772..282bcadf67 100644
--- a/server/services/managedVisitors.js
+++ b/server/services/managedVisitors.js
@@ -2,7 +2,7 @@ import { dataPath } from '../lib/paths.js';
import { createManagedVisitorBroker } from './managedVisitorBroker.js';
import { createManagedVisitorHost } from './managedVisitorHost.js';
import { ServerError } from '../lib/errorHandler.js';
-import { isCrossOrigin } from '../../lib/portosAuthCore.js';
+import { isCrossOrigin, isLocalConnection } from '../../lib/portosAuthCore.js';
let broker;
export function getManagedVisitorBroker() {
@@ -11,7 +11,9 @@ export function getManagedVisitorBroker() {
return broker;
}
export async function authenticateManagedVisitorRequest(req, broker = getManagedVisitorBroker()) {
- if (!['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(req.socket?.remoteAddress) || isCrossOrigin(req)) {
+ // The Vite dev proxy (0.0.0.0:5554) reaches the API from its own loopback
+ // socket; its client-address marker names the real caller.
+ if (!isLocalConnection(req.socket?.remoteAddress, req.headers) || isCrossOrigin(req)) {
throw new ServerError('Managed visitor API requires a local same-origin caller.', { status: 403 });
}
const match = /^Bearer (mv1_[a-f0-9]{64})$/i.exec(req.headers.authorization ?? '');