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 (codex): redact peer passwords from client payloads + re-probe on credential change
[._.]/ Adam Eivybc0934c86637
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsxindex a19c3019bd..55df1c4187 100644--- a/client/src/pages/Instances.jsx+++ b/client/src/pages/Instances.jsx@@ -833,10 +833,11 @@ function PeerAuthEditor({ peer, onRefresh }) {const hasAuth = !!peer.auth;const startEdit = () => {- // Prefill from the stored credential so editing the username alone doesn't- // wipe the password (the server replaces the whole credential on save).+ // Prefill the (non-secret) username; the password is never sent to the+ // browser (server redacts it to a hasPassword marker), so it must be+ // re-entered to save — saving replaces the whole credential server-side.setUsername(peer.auth?.username || '');- setPassword(peer.auth?.password || '');+ setPassword('');setEditing(true);};@@ -875,7 +876,7 @@ function PeerAuthEditor({ peer, onRefresh }) {value={password}onChange={e => setPassword(e.target.value)}onKeyDown={e => e.key === 'Enter' && save()}- placeholder="password"+ placeholder={hasAuth ? 're-enter password to update' : 'password'}type="password"autoComplete="new-password"className="bg-port-bg border border-port-border rounded px-2 py-0.5 text-xs text-white focus:outline-hidden focus:border-port-accent flex-1 min-w-[120px]"diff --git a/server/routes/instances.js b/server/routes/instances.jsindex f08afed60a..3ff48fb93a 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -100,7 +100,9 @@ router.get('/', asyncHandler(async (req, res) => {instances.getPeers(),getSyncStatus({ includeChecksums: true })]);- res.json({ self, peers, syncStatus });+ // Redact each peer's stored proxy password (keep username + hasPassword) —+ // the browser never needs the secret. Mirrors providers' hasApiKey pattern.+ res.json({ self, peers: peers.map(instances.sanitizePeerForClient), syncStatus });}));// GET /api/instances/sync-status — local sync sequences + checksums (used by peers during probe)@@ -204,7 +206,7 @@ router.post('/peers', asyncHandler(async (req, res) => {}}const peer = await instances.addPeer(data);- res.status(201).json(peer);+ res.status(201).json(instances.sanitizePeerForClient(peer));}));// PUT /api/instances/peers/:id — update peer@@ -218,7 +220,7 @@ router.put('/peers/:id', asyncHandler(async (req, res) => {}const peer = await instances.updatePeer(req.params.id, data);if (!peer) throw new ServerError('Peer not found', { status: 404 });- res.json(peer);+ res.json(instances.sanitizePeerForClient(peer));}));// DELETE /api/instances/peers/:id — remove peer@@ -232,7 +234,7 @@ router.delete('/peers/:id', asyncHandler(async (req, res) => {router.post('/peers/:id/connect', asyncHandler(async (req, res) => {const result = await instances.connectPeer(req.params.id);if (!result) throw new ServerError('Peer not found', { status: 404 });- res.json(result);+ res.json(instances.sanitizePeerForClient(result));}));// POST /api/instances/peers/:id/probe — force immediate probe@@ -241,7 +243,7 @@ router.post('/peers/:id/probe', asyncHandler(async (req, res) => {const peer = peers.find(p => p.id === req.params.id);if (!peer) throw new ServerError('Peer not found', { status: 404 });const result = await instances.probePeer(peer);- res.json(result);+ res.json(instances.sanitizePeerForClient(result));}));// GET /api/instances/peers/:id/query — proxy GET to peerdiff --git a/server/services/instances.js b/server/services/instances.jsindex 37f573e15d..d2a0a57a39 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -95,6 +95,17 @@ export function redactPeerForWire(peer) {return rest;}+// Redact the stored credential before a peer record is returned to the local+// client (API responses + socket broadcasts). Keeps the non-secret username+// and a `hasPassword` marker so the UI can show "credential set" and prefill+// the username, but never ships the password to the browser — mirrors the+// `hasApiKey` pattern in server/routes/providers.js. The password stays only+// on the server-side record, where peerAuthHeaders reads it.+export function sanitizePeerForClient(peer) {+ if (!peer || typeof peer !== 'object' || !peer.auth || typeof peer.auth !== 'object') return peer;+ return { ...peer, auth: { username: peer.auth.username ?? '', hasPassword: Boolean(peer.auth.password) } };+}+// Default data shapeconst DEFAULT_DATA = {self: null,@@ -340,6 +351,15 @@ export async function updatePeer(id, updates) {// reconnect using the new URL on the next probe cycle. Invalid/no-op host// writes no longer disrupt an already-healthy connection.if (updates.enabled === false || hostChanged || authChanged) disconnectFromPeer(id);+ // A credential edit is almost always the fix for a 401, but the peer may be+ // deep in exponential probe backoff (up to 24h) from those failures — so the+ // regular poll loop would skip it for hours. Retry immediately: probePeer+ // bypasses the nextProbeAt gate and, on success, resets backoff + reconnects+ // the relay with the new credential. Fire-and-forget; failure just re-arms+ // backoff as before.+ if (authChanged && result && result.enabled !== false) {+ probePeer(result).catch((err) => console.log(`⚠️ Probe after credential change failed: ${err.message}`));+ }// Backfill-subscribe every local record of any kind whose category just// flipped on. Fire-and-forget — `autoSubscribePeerToAllRecords` is// idempotent + per-record-error tolerant, and we don't want to block thediff --git a/server/services/instances.test.js b/server/services/instances.test.jsindex 4d033e5682..ae9385d5c6 100644--- a/server/services/instances.test.js+++ b/server/services/instances.test.js@@ -60,6 +60,7 @@ import {queryPeer,handleAnnounce,redactPeerForWire,+ sanitizePeerForClient,startPolling,stopPolling} from './instances.js';@@ -323,6 +324,24 @@ describe('instances.js', () => {});});+ describe('sanitizePeerForClient', () => {+ it('redacts the password to a hasPassword marker but keeps the username', () => {+ const peer = { id: 'peer-1', name: 'host', auth: { username: 'alice', password: 'secret' }, status: 'online' };+ const sanitized = sanitizePeerForClient(peer);++ expect(sanitized.auth).toEqual({ username: 'alice', hasPassword: true });+ expect(sanitized.auth.password).toBeUndefined();+ expect(sanitized).toMatchObject({ id: 'peer-1', status: 'online' });+ // Original (server-side record) keeps the real password+ expect(peer.auth.password).toBe('secret');+ });++ it('leaves a credential-less peer untouched', () => {+ const peer = { id: 'peer-1', name: 'host', auth: null };+ expect(sanitizePeerForClient(peer)).toBe(peer);+ });+ });+describe('updatePeer', () => {it('should update peer name', async () => {const peers = [{ id: 'peer-1', name: 'old-name', enabled: true }];@@ -387,24 +406,31 @@ describe('instances.js', () => {expect(result.auth).toEqual({ username: 'bob', password: 'pw' });});- it('should reconnect the socket relay when the credential changes', async () => {- const peers = [{ id: 'peer-1', name: 'host', enabled: true, auth: { username: 'bob', password: 'old' } }];+ it('should reconnect the relay and re-probe immediately when the credential changes', async () => {+ // Peer is deep in backoff from prior 401s — the new credential must+ // trigger an immediate probe, not wait out nextProbeAt.+ const peers = [{ id: 'peer-1', name: 'host', enabled: true, status: 'offline', consecutiveFailures: 5, nextProbeAt: '2999-01-01T00:00:00Z', auth: { username: 'bob', password: 'old' } }];readJSONFile.mockResolvedValue({ self: null, peers });+ fetch.mockRejectedValue(new Error('offline'));await updatePeer('peer-1', { auth: { username: 'bob', password: 'new' } });// Relay pins the Basic header at connect time, so a credential change// must tear it down to reconnect with the new extraHeaders.expect(disconnectFromPeer).toHaveBeenCalledWith('peer-1');+ // Immediate re-probe fired (bypasses the nextProbeAt backoff gate).+ expect(fetch).toHaveBeenCalled();});- it('should NOT reconnect the socket relay on a no-op credential write', async () => {+ it('should NOT reconnect or re-probe on a no-op credential write', async () => {const peers = [{ id: 'peer-1', name: 'host', enabled: true, auth: { username: 'bob', password: 'pw' } }];readJSONFile.mockResolvedValue({ self: null, peers });+ fetch.mockRejectedValue(new Error('offline'));await updatePeer('peer-1', { auth: { username: 'bob', password: 'pw' } });expect(disconnectFromPeer).not.toHaveBeenCalled();+ expect(fetch).not.toHaveBeenCalled();});it('should not disconnect when enabling a peer', async () => {diff --git a/server/services/socket.js b/server/services/socket.jsindex aaaa1d75bb..35b33984d1 100644--- a/server/services/socket.js+++ b/server/services/socket.js@@ -16,6 +16,7 @@ import { brainEvents } from './brainStorage.js';import { moltworldWsEvents } from './moltworldWs.js';import { queueEvents } from './moltworldQueue.js';import { instanceEvents } from './instanceEvents.js';+import { sanitizePeerForClient } from './instances.js';import { reviewEvents } from './review.js';import { loopEvents } from './loops.js';import { imageGenEvents } from './imageGenEvents.js';@@ -835,7 +836,13 @@ function broadcastToInstances(event, data) { broadcastToSet(instanceSubscribers,// Set up instance event forwardingfunction setupInstanceEventForwarding() {- instanceEvents.on('peers:updated', (data) => broadcastToInstances('instances:peers:updated', data));+ // Redact each peer's stored proxy password before it reaches the browser+ // (keep username + hasPassword) — same secret-stripping the GET /instances+ // route applies. `data` is the full peers array.+ instanceEvents.on('peers:updated', (data) => {+ const sanitized = Array.isArray(data) ? data.map(sanitizePeerForClient) : data;+ broadcastToInstances('instances:peers:updated', sanitized);+ });}// Set up peer agent event forwarding (remote agent streaming)