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 matching source address before an announce can redirect a stored peer (#8354)

[._.]/ Adam Eivy089e909f393e
diff --git a/server/services/instances.js b/server/services/instances.js
index 34fea530bf..909f84e998 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -919,15 +919,38 @@ export async function handleAnnounce({ address, port, instanceId, name, host })
const result = await withData(async (data) => {
// Check for existing peer by instanceId
let existing = data.peers.find(p => p.instanceId === instanceId);
+ // instanceId is public (GET /api/system/health returns it unauthenticated),
+ // so a match on instanceId alone does not prove the caller IS that peer —
+ // only that it knows a public value. Track whether the match instead came
+ // through the address+port fallback below, where the caller's address is
+ // already part of the match.
+ let matchedByAddress = false;
// Fallback: check by address + port
if (!existing) {
existing = data.peers.find(p => p.address === address && p.port === port);
+ matchedByAddress = true;
}
const normalizedHost = validHost(host);
if (existing?.syncSecret) return { created: false, peer: existing };
+ // A forged announce: instanceId matches a stored peer, but the caller's
+ // source address does not match the stored one. Record the sighting only
+ // — never let it teach host/port/name/status, or an attacker who merely
+ // reads a peer's public instanceId could redirect our future requests
+ // (and the peer's Basic credential) to a host they control.
+ // Exempt tailcat: its stored `address` is intentionally the LOCAL forward's
+ // loopback address, never the remote caller's — a mismatch there is the
+ // normal case, not a forgery signal, and its host/port are already pinned
+ // to the local forward by the `transport !== 'tailcat'` guards below.
+ if (existing && !matchedByAddress && existing.transport !== 'tailcat' && existing.address !== address) {
+ console.warn(`⚠️ Peer announce instanceId matched but address mismatched (expected ${existing.address}, got ${address}) — ignoring host/port/name update`);
+ existing.lastSeen = new Date().toISOString();
+ instanceEvents.emit('peers:updated', data.peers);
+ return { created: false, peer: existing };
+ }
+
if (existing) {
existing.lastSeen = new Date().toISOString();
existing.status = 'online';
diff --git a/server/services/instances.test.js b/server/services/instances.test.js
index 9333efa6ef..b0607fac49 100644
--- a/server/services/instances.test.js
+++ b/server/services/instances.test.js
@@ -60,6 +60,7 @@ import { readJSONFile, atomicWrite } from '../lib/fileUtils.js';
import { getTailscaleStatus } from '../lib/tailscale.js';
import { instanceEvents } from './instanceEvents.js';
import { connectToPeer, disconnectFromPeer } from './peerSocketRelay.js';
+import { peerBaseUrl } from '../lib/peerUrl.js';
import {
getPeers,
getAssignableInstances,
@@ -1504,6 +1505,32 @@ describe('instances.js', () => {
expect(peer).toEqual(before);
});
+ it('ignores host/port/name/status from an announce whose address does not match the stored peer, even without a syncSecret', async () => {
+ // instanceId is public (GET /api/system/health, unauthenticated), so a caller
+ // that only knows it — but isn't calling from the peer's real address — must
+ // not be able to redirect this peer record to a host of their choosing.
+ const peer = {
+ id: 'peer-local', instanceId: 'peer-a', address: '192.0.2.10', port: 5555,
+ host: 'configured.example.com', name: 'configured.example.com', status: 'offline',
+ directions: ['outbound']
+ };
+ const before = structuredClone(peer);
+ readJSONFile.mockResolvedValue({ self: { instanceId: 'local-instance' }, peers: [peer] });
+
+ const result = await handleAnnounce({
+ instanceId: 'peer-a', address: '198.51.100.99', port: 443,
+ host: 'attacker.example.com', name: 'attacker'
+ });
+
+ expect(result.created).toBe(false);
+ expect(result.peer.host).toBe(before.host);
+ expect(result.peer.port).toBe(before.port);
+ expect(result.peer.name).toBe(before.name);
+ expect(result.peer.status).toBe(before.status);
+ expect(result.peer.directions).toEqual(before.directions);
+ expect(peerBaseUrl(result.peer)).toBe(peerBaseUrl(before));
+ });
+
it('preserves the managed tailcat endpoint when the remote announces its own host and port', async () => {
const existing = {
id: 'tailcat-peer', address: '127.0.0.1', port: 15555, host: null,