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: cross-platform PATH delim, guard JSON.parse, validate POST host, handle avatar stream errors
Adam Eivy1a30c71a4757
diff --git a/server/lib/tailscale.js b/server/lib/tailscale.jsindex 7f4406389d..3a34d6476e 100644--- a/server/lib/tailscale.js+++ b/server/lib/tailscale.js@@ -1,5 +1,5 @@import { existsSync } from 'fs';-import { join } from 'path';+import { join, delimiter } from 'path';// Paths where the Tailscale CLI binary is commonly found. On macOS the GUI app// doesn't put the CLI in PATH by default; Homebrew installs to /usr/local/bin@@ -15,7 +15,9 @@ export function findTailscale() {for (const p of TAILSCALE_CANDIDATES) {if (existsSync(p)) return p;}- for (const dir of (process.env.PATH || '').split(':')) {+ // Use path.delimiter (';' on Windows, ':' elsewhere) so PATH scanning works cross-platform.+ for (const dir of (process.env.PATH || '').split(delimiter)) {+ if (!dir) continue;const p = join(dir, 'tailscale');if (existsSync(p)) return p;}diff --git a/server/routes/avatar.js b/server/routes/avatar.jsindex 5960ab0de1..971b80bd61 100644--- a/server/routes/avatar.js+++ b/server/routes/avatar.js@@ -23,7 +23,18 @@ router.get('/model.glb', (req, res) => {}res.set('Content-Type', 'model/gltf-binary');res.set('Cache-Control', 'public, max-age=60');- createReadStream(AVATAR_PATH).pipe(res);+ // Guard against TOCTOU: if the file is removed between existsSync() and+ // createReadStream(), the stream emits 'error' — handle it instead of crashing.+ const stream = createReadStream(AVATAR_PATH);+ stream.on('error', (err) => {+ console.warn(`⚠️ Avatar stream error: ${err.code || err.message}`);+ if (!res.headersSent) {+ res.status(err.code === 'ENOENT' ? 404 : 500).json({ error: 'Avatar model unavailable' });+ } else {+ res.destroy(err);+ }+ });+ stream.pipe(res);});export default router;diff --git a/server/routes/instances.js b/server/routes/instances.jsindex 72cdc79639..024827f538 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -16,6 +16,16 @@ import { findTailscale } from '../lib/tailscale.js';const execFileAsync = promisify(execFile);+// Safely parse JSON, returning null on malformed input. Used when consuming CLI output+// that may interleave warnings with the JSON payload or be partial.+function safeJsonParse(str) {+ try {+ return JSON.parse(str);+ } catch {+ return null;+ }+}+const router = Router();// Validation schemas@@ -84,7 +94,9 @@ router.get('/tailnet-suffix', asyncHandler(async (req, res) => {if (!bin) return res.json({ suffix: null, reason: 'tailscale-not-installed' });const { stdout } = await execFileAsync(bin, ['status', '--json']).catch(() => ({ stdout: null }));if (!stdout) return res.json({ suffix: null, reason: 'tailscale-not-running' });- const status = JSON.parse(stdout);+ // Guard against non-JSON output (warnings, partial reads, etc.) so we never 500 the endpoint.+ const status = safeJsonParse(stdout);+ if (!status) return res.json({ suffix: null, reason: 'tailscale-parse-error' });const suffix = status?.CurrentTailnet?.MagicDNSSuffix ?? status?.MagicDNSSuffix ?? null;// Also include the peer map so the UI can auto-match a peer's instanceId/hostname// to its tailnet DNS name without asking the peer.@@ -139,6 +151,13 @@ router.post('/peers/announce', asyncHandler(async (req, res) => {// POST /api/instances/peers — add a peerrouter.post('/peers', asyncHandler(async (req, res) => {const data = addPeerSchema.parse(req.body);+ // Reject invalid DNS names up front so the UI gets a clear error instead of+ // addPeer() silently dropping the field (validHost returns undefined for invalid input).+ if (data.host !== undefined && data.host !== null && data.host !== '') {+ if (instances.validHost(data.host) === undefined) {+ throw new ServerError('Invalid DNS host — use a hostname like "machine.tailnet.ts.net"', { status: 400 });+ }+ }const peer = await instances.addPeer(data);res.status(201).json(peer);}));