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: address review — follow symlinks in workspace check; >= disk thresholds; clean javascript: URI strip

Adam Eivy562df38838d0
diff --git a/client/src/components/messages/MessageDetail.jsx b/client/src/components/messages/MessageDetail.jsx
index ff72d14c6a..f7b6290499 100644
--- a/client/src/components/messages/MessageDetail.jsx
+++ b/client/src/components/messages/MessageDetail.jsx
@@ -21,7 +21,12 @@ function SafeHtmlBody({ html }) {
.replace(/<svg\b[^<]*(?:(?!<\/svg>)<[^<]*)*<\/svg>/gi, '')
.replace(/\s+on\w+\s*=\s*["'][^"']*["']/gi, '')
.replace(/\s+on\w+\s*=\s*\S+/gi, '')
- .replace(/(href|src)\s*=\s*["']\s*javascript:[^"']*/gi, '$1="#"');
+ // Match the full quoted attribute value (capture the quote char so we
+ // consume the closing quote too) — prevents leaving a stray trailing
+ // quote in the output like `href="#""`.
+ .replace(/(href|src)\s*=\s*(["'])\s*javascript:[^"']*\2/gi, '$1="#"')
+ // Also handle unquoted attributes, which end at whitespace or `>`.
+ .replace(/(href|src)\s*=\s*javascript:[^\s>]*/gi, '$1="#"');
const doc = iframe.contentDocument;
if (!doc) return;
diff --git a/server/routes/commands.js b/server/routes/commands.js
index fef6e7c309..b797030af3 100644
--- a/server/routes/commands.js
+++ b/server/routes/commands.js
@@ -1,5 +1,5 @@
import { Router } from 'express';
-import { existsSync, statSync } from 'fs';
+import { existsSync, statSync, realpathSync } from 'fs';
import { resolve, relative, isAbsolute } from 'path';
import { homedir } from 'os';
import * as commands from '../services/commands.js';
@@ -8,9 +8,16 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
const router = Router();
-// Allowed workspace roots: user home and /tmp (normalized via resolve so they
-// match regardless of trailing separators or relative forms).
-const ALLOWED_WORKSPACE_ROOTS = [homedir(), '/tmp'].map(r => resolve(r));
+// Allowed workspace roots: user home and /tmp. Resolve symlinks too so that
+// e.g. a symlinked /tmp on macOS (which points to /private/tmp) still matches
+// after we realpath() the caller's workspacePath.
+const ALLOWED_WORKSPACE_ROOTS = [homedir(), '/tmp']
+ .map(r => {
+ const abs = resolve(r);
+ // Falls back to the resolved path if the root doesn't exist yet — callers
+ // providing paths under a non-existent root will fail the existence check.
+ try { return realpathSync(abs); } catch { return abs; }
+ });
// Separator-safe containment: resolvedPath === root or is a descendant of root.
function isWithinRoot(resolvedPath, root) {
@@ -27,19 +34,23 @@ router.post('/execute', asyncHandler(async (req, res) => {
throw new ServerError('Command is required', { status: 400, code: 'MISSING_COMMAND' });
}
- // Validate workspacePath if provided: must exist, be a directory, and resolve within allowed roots
+ // Validate workspacePath if provided: must exist, be a directory, and — after
+ // symlinks are followed — resolve within an allowed root. Using realpath here
+ // prevents a symlink like /tmp/escape -> /etc from tricking the containment
+ // check (which only sees /tmp/escape).
if (workspacePath) {
const resolvedPath = resolve(workspacePath);
- const isAllowed = ALLOWED_WORKSPACE_ROOTS.some(root => isWithinRoot(resolvedPath, root));
- if (!isAllowed) {
- throw new ServerError('workspacePath is outside allowed directories', { status: 400, code: 'INVALID_PATH' });
- }
if (!existsSync(resolvedPath)) {
throw new ServerError('workspacePath does not exist', { status: 400, code: 'INVALID_PATH' });
}
if (!statSync(resolvedPath).isDirectory()) {
throw new ServerError('workspacePath is not a directory', { status: 400, code: 'INVALID_PATH' });
}
+ const realPath = realpathSync(resolvedPath);
+ const isAllowed = ALLOWED_WORKSPACE_ROOTS.some(root => isWithinRoot(realPath, root));
+ if (!isAllowed) {
+ throw new ServerError('workspacePath is outside allowed directories', { status: 400, code: 'INVALID_PATH' });
+ }
}
const io = req.app.get('io');
diff --git a/server/routes/systemHealth.js b/server/routes/systemHealth.js
index bd39009931..1a2309711e 100644
--- a/server/routes/systemHealth.js
+++ b/server/routes/systemHealth.js
@@ -109,12 +109,12 @@ router.get('/health/details', async (req, res) => {
}
if (disk) {
- if (disk.usagePercent > 95) {
+ if (disk.usagePercent >= 95) {
overallHealth = 'critical';
- warnings.push({ type: 'disk', message: 'Disk usage above 95%' });
- } else if (disk.usagePercent > 85) {
+ warnings.push({ type: 'disk', message: 'Disk usage at or above 95%' });
+ } else if (disk.usagePercent >= 85) {
if (overallHealth !== 'critical') overallHealth = 'warning';
- warnings.push({ type: 'disk', message: 'Disk usage above 85%' });
+ warnings.push({ type: 'disk', message: 'Disk usage at or above 85%' });
}
}