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 — static Tailwind classes and separator-safe path containment

Adam Eivyd544f4536481
diff --git a/client/src/components/wiki/constants.jsx b/client/src/components/wiki/constants.jsx
index 90aea4f355..50e84ab873 100644
--- a/client/src/components/wiki/constants.jsx
+++ b/client/src/components/wiki/constants.jsx
@@ -1,12 +1,15 @@
import { FileText, Users, Lightbulb, GitCompare, Layers, HelpCircle } from 'lucide-react';
+// Tailwind requires concrete class names in source for its content scanner;
+// dynamic strings like `text-${color}` are not emitted. Each category holds
+// its `textClass` explicitly so the JIT compiler keeps the utility.
export const WIKI_CATEGORIES = [
- { key: 'sources', folder: 'wiki/sources', label: 'Sources', icon: FileText, color: 'port-accent', hex: '#3b82f6' },
- { key: 'entities', folder: 'wiki/entities', label: 'Entities', icon: Users, color: 'port-success', hex: '#22c55e' },
- { key: 'concepts', folder: 'wiki/concepts', label: 'Concepts', icon: Lightbulb, color: 'port-warning', hex: '#f59e0b' },
- { key: 'comparisons', folder: 'wiki/comparisons', label: 'Comparisons', icon: GitCompare, color: 'purple-400', hex: '#a855f7' },
- { key: 'synthesis', folder: 'wiki/synthesis', label: 'Synthesis', icon: Layers, color: 'cyan-400', hex: '#06b6d4' },
- { key: 'queries', folder: 'wiki/queries', label: 'Queries', icon: HelpCircle, color: 'pink-400', hex: '#ec4899' }
+ { key: 'sources', folder: 'wiki/sources', label: 'Sources', icon: FileText, color: 'port-accent', textClass: 'text-port-accent', hex: '#3b82f6' },
+ { key: 'entities', folder: 'wiki/entities', label: 'Entities', icon: Users, color: 'port-success', textClass: 'text-port-success', hex: '#22c55e' },
+ { key: 'concepts', folder: 'wiki/concepts', label: 'Concepts', icon: Lightbulb, color: 'port-warning', textClass: 'text-port-warning', hex: '#f59e0b' },
+ { key: 'comparisons', folder: 'wiki/comparisons', label: 'Comparisons', icon: GitCompare, color: 'purple-400', textClass: 'text-purple-400', hex: '#a855f7' },
+ { key: 'synthesis', folder: 'wiki/synthesis', label: 'Synthesis', icon: Layers, color: 'cyan-400', textClass: 'text-cyan-400', hex: '#06b6d4' },
+ { key: 'queries', folder: 'wiki/queries', label: 'Queries', icon: HelpCircle, color: 'pink-400', textClass: 'text-pink-400', hex: '#ec4899' }
];
export function PageTypeIcon({ folder }) {
@@ -14,5 +17,5 @@ export function PageTypeIcon({ folder }) {
const cat = WIKI_CATEGORIES.find(c => c.key === type);
if (!cat) return <FileText size={14} className="text-gray-500 shrink-0" />;
const Icon = cat.icon;
- return <Icon size={14} className={`text-${cat.color} shrink-0`} />;
+ return <Icon size={14} className={`${cat.textClass} shrink-0`} />;
}
diff --git a/client/src/components/wiki/tabs/BrowseTab.jsx b/client/src/components/wiki/tabs/BrowseTab.jsx
index 49767502c9..7babd9a8d8 100644
--- a/client/src/components/wiki/tabs/BrowseTab.jsx
+++ b/client/src/components/wiki/tabs/BrowseTab.jsx
@@ -10,7 +10,7 @@ import toast from '../../ui/Toast';
import { timeAgo, formatBytes } from '../../../utils/formatters';
import { WIKI_CATEGORIES } from '../constants.jsx';
-const WIKI_FOLDERS = WIKI_CATEGORIES.map(c => ({ key: c.folder, label: c.label, icon: c.icon, color: `text-${c.color}` }));
+const WIKI_FOLDERS = WIKI_CATEGORIES.map(c => ({ key: c.folder, label: c.label, icon: c.icon, color: c.textClass }));
const RAW_FOLDERS = [{ key: 'raw', label: 'Raw Sources', icon: FolderOpen, color: 'text-gray-400' }];
export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefresh }) {
diff --git a/client/src/components/wiki/tabs/OverviewTab.jsx b/client/src/components/wiki/tabs/OverviewTab.jsx
index 438f79d3d4..0bbb8e9278 100644
--- a/client/src/components/wiki/tabs/OverviewTab.jsx
+++ b/client/src/components/wiki/tabs/OverviewTab.jsx
@@ -40,7 +40,7 @@ export default function OverviewTab({ vaultId, stats, notes, allNotes, onRefresh
</div>
{WIKI_CATEGORIES.map(cat => (
<div key={cat.key} className="bg-port-card border border-port-border rounded-lg p-4 text-center">
- <cat.icon className={`w-5 h-5 text-${cat.color} mx-auto mb-1`} />
+ <cat.icon className={`w-5 h-5 ${cat.textClass} mx-auto mb-1`} />
<div className="text-2xl font-bold text-white">{stats[cat.key]}</div>
<div className="text-xs text-gray-500">{cat.label}</div>
</div>
diff --git a/server/routes/commands.js b/server/routes/commands.js
index 60f3a41a7c..fef6e7c309 100644
--- a/server/routes/commands.js
+++ b/server/routes/commands.js
@@ -1,6 +1,6 @@
import { Router } from 'express';
import { existsSync, statSync } from 'fs';
-import { resolve } from 'path';
+import { resolve, relative, isAbsolute } from 'path';
import { homedir } from 'os';
import * as commands from '../services/commands.js';
import * as pm2Service from '../services/pm2.js';
@@ -8,8 +8,16 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
const router = Router();
-// Allowed workspace roots: user home and /tmp
-const ALLOWED_WORKSPACE_ROOTS = [homedir(), '/tmp'];
+// 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));
+
+// Separator-safe containment: resolvedPath === root or is a descendant of root.
+function isWithinRoot(resolvedPath, root) {
+ if (resolvedPath === root) return true;
+ const rel = relative(root, resolvedPath);
+ return !!rel && !rel.startsWith('..') && !isAbsolute(rel);
+}
// POST /api/commands/execute - Execute a command
router.post('/execute', asyncHandler(async (req, res) => {
@@ -22,7 +30,7 @@ router.post('/execute', asyncHandler(async (req, res) => {
// Validate workspacePath if provided: must exist, be a directory, and resolve within allowed roots
if (workspacePath) {
const resolvedPath = resolve(workspacePath);
- const isAllowed = ALLOWED_WORKSPACE_ROOTS.some(root => resolvedPath === root || resolvedPath.startsWith(root + '/'));
+ 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' });
}
diff --git a/server/services/backup.js b/server/services/backup.js
index adffcaf5a5..3711b3a5de 100644
--- a/server/services/backup.js
+++ b/server/services/backup.js
@@ -10,7 +10,7 @@ import { spawn } from 'child_process';
import { createHash } from 'crypto';
import { createReadStream } from 'fs';
import { access, readFile, readdir, stat, writeFile } from 'fs/promises';
-import { join, resolve } from 'path';
+import { join, resolve, relative, isAbsolute } from 'path';
import { PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';
import { getEvent } from './eventScheduler.js';
import { checkHealth } from '../lib/db.js';
@@ -290,9 +290,12 @@ export async function restoreSnapshot(destPath, snapshotId, { dryRun = true, sub
throw new Error(`Invalid snapshotId: ${snapshotId}`);
}
const srcDir = join(destPath, 'snapshots', snapshotId, 'data');
- // Containment check: resolved path must stay within the snapshots directory
+ // Containment check: resolved path must stay within the snapshots directory.
+ // Use path.relative to stay cross-platform and avoid prefix-match pitfalls
+ // (e.g. /snaps vs /snaps2).
const snapshotsRoot = resolve(join(destPath, 'snapshots'));
- if (!resolve(srcDir).startsWith(snapshotsRoot + '/')) {
+ const rel = relative(snapshotsRoot, resolve(srcDir));
+ if (!rel || rel.startsWith('..') || isAbsolute(rel)) {
throw new Error(`Path traversal detected for snapshotId: ${snapshotId}`);
}
diff --git a/server/services/dataManager.js b/server/services/dataManager.js
index d0ef83c25a..a6f69f61c7 100644
--- a/server/services/dataManager.js
+++ b/server/services/dataManager.js
@@ -1,5 +1,5 @@
import { readdir, stat, rm, mkdir, writeFile as fsWriteFile } from 'fs/promises';
-import { join, relative, resolve } from 'path';
+import { join, relative, resolve, isAbsolute } from 'path';
import { existsSync } from 'fs';
import { execFile } from 'child_process';
import { promisify } from 'util';
@@ -169,10 +169,13 @@ export async function purgeCategory(categoryKey, options = {}) {
if (!existsSync(dirPath)) throw new Error(`Category directory not found: ${categoryKey}`);
if (options.subPath) {
+ const resolvedRoot = resolve(dirPath);
const resolvedTarget = resolve(join(dirPath, options.subPath));
- if (!resolvedTarget.startsWith(resolve(dirPath))) throw new Error('Invalid subPath');
- const targetPath = resolvedTarget;
- await rm(targetPath, { recursive: true, force: true });
+ // Boundary-aware containment check: use path.relative so a prefix like
+ // `/data/cat` cannot satisfy containment for `/data/cat2`.
+ const rel = relative(resolvedRoot, resolvedTarget);
+ if (!rel || rel.startsWith('..') || isAbsolute(rel)) throw new Error('Invalid subPath');
+ await rm(resolvedTarget, { recursive: true, force: true });
} else {
const entries = await readdir(dirPath).catch(() => []);
await Promise.all(entries.map(entry => rm(join(dirPath, entry), { recursive: true, force: true })));