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
address review (claude): stop credential-metadata leak + fix echo guard on partial maps
Adam Eivy1c8cdd856826
diff --git a/server/routes/instances.js b/server/routes/instances.jsindex c08bd71bba..b190ea54f2 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -100,8 +100,10 @@ const querySchema = z.object({// announcing peer's identity (matched against our peer record).const reciprocalSyncSchema = z.object({instanceId: z.string().guid(),- // `.unwrap()` strips the `.optional()` from the shared schema — the category- // map is required on this endpoint (an empty/absent map has nothing to mirror).+ // `.unwrap()` strips the `.optional()` from the shared schema so the+ // syncCategories KEY is required. An empty `{}` still parses (all fields are+ // optional) and simply no-ops downstream in applyReciprocalSync+ // (sanitizeSyncCategories returns null → changed:false).syncCategories: syncCategoriesSchema.unwrap()});@@ -255,10 +257,14 @@ router.post('/peers/:id/connect', asyncHandler(async (req, res) => {// instanceId in the body (we may not know its local-peer-id mapping).router.post('/peers/sync-categories', asyncHandler(async (req, res) => {const data = reciprocalSyncSchema.parse(req.body);- const { changed, peer } = await instances.applyReciprocalSync(data.instanceId, data.syncCategories);+ const { changed } = await instances.applyReciprocalSync(data.instanceId, data.syncCategories);// 200 even when the peer is unknown to us / nothing changed — this is a- // best-effort convergence signal, not a command that must succeed.- res.json({ applied: changed, peer: peer ? instances.sanitizePeerForClient(peer) : null });+ // best-effort convergence signal, not a command that must succeed. We return+ // only `applied` (not the peer record) — the remote caller doesn't consume it,+ // and echoing our peer entry would leak our stored proxy-credential metadata+ // (username + hasPassword) for reaching them across the peer boundary, the+ // same leak the /announce route guards against with redactPeerForWire.+ res.json({ applied: changed });}));// POST /api/instances/peers/:id/reciprocate — explicit "make all enableddiff --git a/server/services/instances.js b/server/services/instances.jsindex 1580560650..92ae5f059c 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -728,7 +728,10 @@ export async function applyReciprocalSync(instanceId, categories) {const peer = await withData(async (data) => {const entry = data.peers.find(p => p.instanceId === instanceId);if (!entry) return null;- const prev = entry.syncCategories || { ...DEFAULT_SYNC_CATEGORIES };+ // Default the baseline so a partial stored map doesn't make absent-vs-false+ // diverge — otherwise sanitized adding `goals:false` to a `prev` missing+ // `goals` reads as a change (`false !== undefined`) and defeats the guard.+ const prev = { ...DEFAULT_SYNC_CATEGORIES, ...(entry.syncCategories || {}) };const next = { ...prev, ...sanitized };// No-op when nothing actually flips — the echo guard.if (Object.keys(next).every(k => next[k] === prev[k])) return entry;diff --git a/server/services/instances.test.js b/server/services/instances.test.jsindex e1592af54f..d41ebed570 100644--- a/server/services/instances.test.js+++ b/server/services/instances.test.js@@ -565,6 +565,18 @@ describe('instances.js', () => {expect(changed).toBe(false);});+ it('echo guard treats absent-vs-false alike: adding goals:false to a partial map is a no-op', async () => {+ // prev is a partial map missing `goals`; incoming sets goals:false, which+ // is already the effective state → must NOT report changed (the baseline+ // is defaulted so `false !== undefined` can't spuriously trip the guard).+ const peers = [{ id: 'p1', instanceId: 'inst-A', name: 'A', syncCategories: { brain: true } }];+ readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers });++ const { changed } = await applyReciprocalSync('inst-A', { goals: false });++ expect(changed).toBe(false);+ });+it('returns changed:false for an unknown peer instanceId', async () => {readJSONFile.mockResolvedValue({ self: { instanceId: 'me' }, peers: [] });const { changed, peer } = await applyReciprocalSync('nope', { brain: true });