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: require operator authority to repoint outbound endpoints and store paths

[._.]/ Adam Eivyf183cfdf8d5d
diff --git a/server/lib/README.md b/server/lib/README.md
index 8ea4680ffe..1335358521 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -675,7 +675,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
|---|---|
| `apiAccessPolicy.js` | Shared always-public path, gated non-`/api` prefix, and peer-credential federation surface (`PEER_API_SURFACE`, `isPeerApiRequestAllowed`) policy consumed by `authGate` and API discovery. |
| `apiCatalog.js` | Searchable projection of the Express route inventory (`getApiRouteCatalog()` from `apiRouteGraph.js`): domain, access, side-effect, contract coverage, summaries, and Express-to-OpenAPI path conversion. |
-| `hostControlRoutes.js` | The audited `HOST_CONTROL_ROUTES` list of HTTP routes that execute on the host (app lifecycle, CoS agent queueing, git, scaffold, standardize, feature agents, loops, GSD, local review, provider execution config, autopilot start) plus `hostControlRouteFor` / `isHostControlRoute`; `authGate.js#hostControlRouteGate` applies `requireHostControl` to every entry. `hostControlBodyKeys` names the execution-policy keys of a `PUT /api/settings`, `PATCH /api/settings/slice`, or `PUT /api/cos/config` body (`HOST_CONTROL_SETTINGS_SLICES`, `HOST_CONTROL_OPEN_COS_CONFIG_KEYS`), and `hostControlSettingsPathsIn` / `changedHostControlSettingsPaths` the nested settings keys that pick an executable (`HOST_CONTROL_SETTINGS_PATHS`, gated only when the value changes). `voiceConfigHostControlPathsIn` / `changedVoiceConfigHostControlPaths` do the same for the voice agent's instructions and coding-agent switch (`HOST_CONTROL_VOICE_CONFIG_PATHS` on `PUT /api/voice/config`). All of these are gated by `authGate.js#hostControlBodyGate`. The socket twin is `HOST_CONTROL_SOCKET_EVENTS` in `services/socket.js`. |
+| `hostControlRoutes.js` | The audited `HOST_CONTROL_ROUTES` list of HTTP routes that execute on the host (app lifecycle, CoS agent queueing, git, scaffold, standardize, feature agents, loops, GSD, local review, provider execution config, autopilot start) plus `hostControlRouteFor` / `isHostControlRoute`; `authGate.js#hostControlRouteGate` applies `requireHostControl` to every entry. `hostControlBodyKeys` names the execution-policy keys of a `PUT /api/settings`, `PATCH /api/settings/slice`, or `PUT /api/cos/config` body (`HOST_CONTROL_SETTINGS_SLICES`, `HOST_CONTROL_OPEN_COS_CONFIG_KEYS`), and `hostControlSettingsPathsIn` / `changedHostControlSettingsPaths` the nested settings keys that pick an executable, an outbound endpoint or a host data file (`HOST_CONTROL_SETTINGS_PATHS`, gated only when the value changes). `voiceConfigHostControlPathsIn` / `changedVoiceConfigHostControlPaths` do the same for the voice agent's instructions, coding-agent switch and STT endpoint (`HOST_CONTROL_VOICE_CONFIG_PATHS` on `PUT /api/voice/config`). All of these are gated by `authGate.js#hostControlBodyGate`. The socket twin is `HOST_CONTROL_SOCKET_EVENTS` in `services/socket.js`. |
| `apiRouteGraph.js` | Static scan of the mounted HTTP route graph — `server/index.js` `app.use('/api/…', router)` mounts → route-module imports → `router.use(prefix, child)` → `router.<method>('<path>')`, including aliased mounts, local subrouters, factory returns and composed `toolkit.routes.<x>` routers. `buildApiRouteCatalog({ repoRoot? })` → `{ derivedFrom, mounts, routes: [{ method, path, mountPath, sources }], stats }`; `getApiRouteCatalog()` derives it on first use and caches it for the process (read by the API Explorer, the internal OpenAPI document and `apiRouteParity.test.js`); `scanRouteGraph()` adds `declarationKeys` / `duplicateDeclarationKeys` (`routeDeclarationKey`) for the coverage guard in `apiRouteGraph.test.js`. Never committed — see "Generated manifests" in `server/AGENTS.md`. |
| `socketEventCatalog.js` | Searchable projection of the cached Socket.IO inventory: direction, domain, and runtime-schema coverage. |
| `sourceScan.js` | Lexer-assisted primitives shared by the whole-tree source-scan guard suites, so the timer rule and the socket rule cannot drift on what "owns its rejection" means. `blankLiterals(src)` blanks comment/string/template/regex CONTENT to spaces while preserving length, so a brace inside a literal cannot skew a bracket walk and a caller can still read a literal (a socket event name) out of the original string at the same offset; `matchBracket(src, open)` returns the index past the matching `)`/`]`/`}`; `parseCallbackAt(blanked, from, limit)` parses the function expression at `from` (`async`/`function`/either arrow spelling, skipping the parameter list as a unit so a `= {}` default is not mistaken for the body) and returns `{isAsync, start, text}`; `unguardedAwaits(body)` returns the awaited chains that neither sit inside a `try`/`catch` nor END in `.catch(…)`. `blankComments(src)` is the weaker LINE-based stripper the per-line `child_process` rule needs. `blankCommentBodies(src)` is the complement — comments blanked, literal TEXT kept — for a caller that reads a message string and must not see a marker written in a comment beside it. Callers: `childProcess.guards.test.js`, `server/timerCallbackConventions.test.js`, `server/logLevelConventions.test.js`, `server/sockets/asyncHandlerGuard.test.js`, `server/process-safety-net.test.js`. |
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.js
index 51ac286032..b48ac8cb95 100644
--- a/server/lib/hostControlRoutes.js
+++ b/server/lib/hostControlRoutes.js
@@ -90,6 +90,17 @@
* reduce execution or remove records.
* - notes (#9007): vault add/repoint gated (chooses the host directory
* note CRUD reads/writes); note CRUD itself stays open.
+ * - Outbound endpoints and host data files: a setting that names a URL
+ * PortOS later sends data to, or a host file it reads and writes, needs
+ * operator authority to change. A remote caller choosing one could send
+ * private audio, text or a stored token to their own server, which can
+ * then redirect the request to PortOS's own loopback port, where it counts
+ * as a local operator. They could also read or write any JSON file the
+ * host user owns. Gated: the voice STT endpoint, the Image Gen external
+ * SD API URL (including its legacy top-level key), the Beeper base URL and
+ * its non-loopback opt-in, the MortalLoom store path (all change-gated,
+ * below) and `PUT /api/lmstudio/config` (base URL plus timeout, in
+ * memory, with no UI writer).
* - browser: navigate uses the configured browser with its URL/IP guards;
* downloads DELETE removes data. Harness models/refresh re-reads the
* configured harness catalog; neither selects or installs an executable.
@@ -137,8 +148,9 @@
* a tool. The mind maintainer watchdog queues remediation and is gated.
* - voice config (#10990): `llm.systemPrompt`, `llm.personality`,
* `llm.tools.enabled` and `llm.codeAgent` are the voice agent's
- * instructions or the switch that arms its coding-agent tool.
- * `PUT /api/voice/config` is gated only when one of those values would
+ * instructions or the switch that arms its coding-agent tool, and
+ * `stt.endpoint` receives microphone audio and returns the transcript
+ * the agent acts on. `PUT /api/voice/config` is gated only when one of those values would
* change (`HOST_CONTROL_VOICE_CONFIG_PATHS`); a whole-config resend and
* every other voice setting stay open.
*
@@ -596,6 +608,9 @@ export const HOST_CONTROL_ROUTES = Object.freeze([
'POST /api/local-llm/upgrade-backend',
'POST /api/local-llm/ollama-service',
'POST /api/local-llm/lmstudio-service',
+ // Base URL every LM Studio completion, embedding and Persistent Mind call
+ // sends user text to; no UI writes it.
+ 'PUT /api/lmstudio/config',
'POST /api/local-llm/llama-server/install',
'POST /api/local-llm/llama-server/upgrade',
'POST /api/local-llm/llama-server/start',
@@ -858,8 +873,9 @@ export const HOST_CONTROL_SETTINGS_SLICES = Object.freeze([
/**
* Nested settings mutation keys, as dotted paths, that choose a binary
* PortOS spawns (the image-gen CLIs and the Python interpreter every local
- * media lane runs) or turn the Layered Intelligence `cmd` sources into a
- * full shell (#8751). Their parent slices stay open, so each is gated per
+ * media lane runs), turn the Layered Intelligence `cmd` sources into a
+ * full shell (#8751), pick an outbound endpoint PortOS sends prompts or a
+ * stored token to, or pick the host file a store reads and rewrites. Their parent slices stay open, so each is gated per
* CHANGED value rather than per presence: the Image Gen tab resends the whole
* slice, stored paths included, on every save, and a remote caller changing
* only an aspect ratio must still be able to save it. A body that omits or
@@ -868,16 +884,22 @@ export const HOST_CONTROL_SETTINGS_SLICES = Object.freeze([
* cleared value as unset — so neither is gated.
*/
export const HOST_CONTROL_SETTINGS_PATHS = Object.freeze([
+ 'beeper.allowNonLoopbackBaseUrl',
+ 'beeper.baseUrl',
'imageGen.agy.agyPath',
'imageGen.codex.codexPath',
+ 'imageGen.external.sdapiUrl',
'imageGen.grok.grokPath',
'imageGen.local.pythonPath',
+ 'imageGen.sdapiUrl',
'layeredIntelligence.trustShellSources',
+ 'mortalloom.path',
]);
/**
- * `PUT /api/voice/config` fields that become the voice agent's instructions
- * or arm its coding-agent tool (#10990). The Voice settings tab resends the
+ * `PUT /api/voice/config` fields that become the voice agent's instructions,
+ * arm its coding-agent tool (#10990), or choose the endpoint that receives the
+ * operator's microphone audio and supplies the transcript the agent acts on. The Voice settings tab resends the
* whole config on every save, so these are gated per CHANGED value: a remote
* caller who only changes the TTS rate must still be able to save.
* `llm.personality` and `llm.codeAgent` compare as whole objects.
@@ -887,6 +909,7 @@ export const HOST_CONTROL_VOICE_CONFIG_PATHS = Object.freeze([
'llm.personality',
'llm.tools.enabled',
'llm.codeAgent',
+ 'stt.endpoint',
]);
/**
diff --git a/server/services/authGate.test.js b/server/services/authGate.test.js
index 0f63fb1bdb..b38f61ae14 100644
--- a/server/services/authGate.test.js
+++ b/server/services/authGate.test.js
@@ -887,6 +887,91 @@ describe('mounted host-control trailing slashes (#8950)', () => {
});
});
+// A remote caller who picks where PortOS sends audio, prompts or a stored
+// token can read them, answer with forged results, or 307 the request back to
+// PortOS's own loopback port, where it counts as a local operator. Picking a
+// store's host file path lets them rewrite any JSON file the host user owns.
+describe('outbound endpoint and host file settings authority', () => {
+ const buildApp = async (remoteAddress = '192.0.2.10') => {
+ const { authGate, hostControlRouteGate, hostControlBodyGate } = await import('./authGate.js');
+ const persist = vi.fn();
+ const ok = (req, res) => { persist(req.body); res.json({ saved: true }); };
+ 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.put('/api/settings', ok);
+ app.patch('/api/settings/slice', ok);
+ app.put('/api/voice/config', ok);
+ app.put('/api/lmstudio/config', ok);
+ return { app, persist };
+ };
+ const attacker = 'http://attacker.example:7860';
+ const redirects = [
+ ['put', '/api/settings', { imageGen: { mode: 'external', external: { sdapiUrl: attacker } } }],
+ ['put', '/api/settings', { imageGen: { sdapiUrl: attacker } }],
+ ['patch', '/api/settings/slice', { slicePath: 'imageGen.external', partial: { sdapiUrl: attacker } }],
+ ['put', '/api/settings', { beeper: { baseUrl: attacker, allowNonLoopbackBaseUrl: true } }],
+ ['patch', '/api/settings/slice', { slicePath: 'beeper', partial: { baseUrl: attacker } }],
+ ['put', '/api/settings', { mortalloom: { enabled: true, path: '/example/target.json' } }],
+ ['put', '/api/voice/config', { stt: { endpoint: attacker } }],
+ ['put', '/api/lmstudio/config', { baseUrl: attacker }],
+ ];
+ const stored = {
+ imageGen: { mode: 'external', sdapiUrl: 'http://192.0.2.20:7860', external: { sdapiUrl: 'http://192.0.2.20:7860' } },
+ beeper: { enabled: true, baseUrl: 'http://localhost:23373', allowNonLoopbackBaseUrl: false },
+ mortalloom: { enabled: true, path: '/example/MortalLoom.json' },
+ };
+
+ it('refuses a remote password-free caller before any write', async () => {
+ mergeSettingsFile(stored);
+ const { app, persist } = await buildApp();
+ for (const [method, path, body] of redirects) {
+ const response = await request(app)[method](path).send(body);
+ expect(response.status, `${method} ${path}`).toBe(403);
+ expect(response.body.code).toBe('HOST_CONTROL_FORBIDDEN');
+ }
+ expect(persist).not.toHaveBeenCalled();
+ });
+
+ it('keeps unchanged resends, clears and unrelated fields open to a remote caller', async () => {
+ mergeSettingsFile(stored);
+ const { app, persist } = await buildApp();
+ const open = [
+ ['put', '/api/settings', { imageGen: { ...stored.imageGen, external: { sdapiUrl: stored.imageGen.external.sdapiUrl, denoise: true } } }],
+ ['put', '/api/settings', { beeper: { ...stored.beeper, intervalMinutes: 30 } }],
+ ['put', '/api/settings', { mortalloom: { enabled: true, path: '' } }],
+ ['put', '/api/voice/config', { stt: { endpoint: 'http://127.0.0.1:5562', language: 'en' } }],
+ ];
+ for (const [method, path, body] of open) {
+ expect((await request(app)[method](path).send(body)).status, JSON.stringify(body)).toBe(200);
+ }
+ expect(persist).toHaveBeenCalledTimes(open.length);
+ });
+
+ it('preserves local and delegated agent operators', async () => {
+ mergeSettingsFile(stored);
+ const local = await buildApp('127.0.0.1');
+ for (const [method, path, body] of redirects) {
+ expect((await request(local.app)[method](path).send(body)).status, `${method} ${path}`).toBe(200);
+ }
+ await (await import('./auth.js')).setPassword({ newPassword: 'example-password' });
+ const { PORTOS_API_TOKEN: token } = await (await import('./agentApiAuth.js')).resolveAgentApiEnv();
+ expect(token).toBeTruthy();
+ const agent = await buildApp();
+ for (const [method, path, body] of redirects) {
+ expect((await request(agent.app)[method](path).set('Authorization', `Bearer ${token}`).send(body)).status, `${method} ${path}`).toBe(200);
+ }
+ expect(local.persist).toHaveBeenCalledTimes(redirects.length);
+ expect(agent.persist).toHaveBeenCalledTimes(redirects.length);
+ });
+});
+
describe('outbound mail dispatch authority (#11273)', () => {
let mailDependencies;