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

address review: fix 5 Copilot review findings (iteration 3)

Adam Eivy227985ef1771
diff --git a/client/src/components/brain/tabs/FeedsTab.jsx b/client/src/components/brain/tabs/FeedsTab.jsx
index bd0976a708..1f1eecd3eb 100644
--- a/client/src/components/brain/tabs/FeedsTab.jsx
+++ b/client/src/components/brain/tabs/FeedsTab.jsx
@@ -97,14 +97,16 @@ export default function FeedsTab({ onRefresh }) {
const handleMarkRead = async (itemId) => {
await api.markFeedItemRead(itemId).catch(() => null);
- setItems(prev => prev.map(i => i.id === itemId ? { ...i, read: true } : i));
- setFeeds(prev => prev.map(f => {
- const item = items.find(i => i.id === itemId);
- if (item?.feedId === f.id && !item.read) {
- return { ...f, unreadCount: Math.max(0, f.unreadCount - 1) };
+ // Track which feed to update before modifying items state
+ setItems(prev => {
+ const item = prev.find(i => i.id === itemId);
+ if (item && !item.read) {
+ setFeeds(fPrev => fPrev.map(f =>
+ f.id === item.feedId ? { ...f, unreadCount: Math.max(0, f.unreadCount - 1) } : f
+ ));
}
- return f;
- }));
+ return prev.map(i => i.id === itemId ? { ...i, read: true } : i);
+ });
};
const handleMarkAllRead = async () => {
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 02e854c276..220319e43c 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -17,7 +17,10 @@ const updateConfigSchema = z.object({
autoConnect: z.boolean().optional(),
headless: z.boolean().optional(),
userDataDir: z.string().optional(),
- downloadDir: z.string().optional()
+ downloadDir: z.string().refine(
+ v => !v || !v.includes('..'),
+ { message: 'downloadDir must not contain path traversal' }
+ ).optional()
});
// GET /api/browser - Full browser status
diff --git a/server/services/feeds.js b/server/services/feeds.js
index 34539d6b66..5f26b49d4b 100644
--- a/server/services/feeds.js
+++ b/server/services/feeds.js
@@ -277,10 +277,29 @@ export async function getFeedStats() {
// ─── Internal Helpers ───────────────────────────────────────────────────────
+// Check if a hostname resolves to a private/loopback/link-local IP
+function isPrivateHost(hostname) {
+ // Block common private/loopback/link-local patterns (pre-DNS resolution)
+ const blocked = ['localhost', '127.0.0.1', '::1', '0.0.0.0', '169.254.169.254'];
+ if (blocked.includes(hostname)) return true;
+ // Block numeric private ranges: 10.x, 172.16-31.x, 192.168.x, 169.254.x
+ const parts = hostname.split('.').map(Number);
+ if (parts.length === 4 && parts.every(p => !isNaN(p))) {
+ if (parts[0] === 10) return true;
+ if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) return true;
+ if (parts[0] === 192 && parts[1] === 168) return true;
+ if (parts[0] === 169 && parts[1] === 254) return true;
+ if (parts[0] === 127) return true;
+ }
+ return false;
+}
+
async function fetchFeedXml(url) {
// Restrict to http/https to prevent SSRF via file://, data://, etc.
const parsed = new URL(url);
if (!['http:', 'https:'].includes(parsed.protocol)) return null;
+ // Block private/loopback/link-local hosts
+ if (isPrivateHost(parsed.hostname)) return null;
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
diff --git a/server/services/syncOrchestrator.js b/server/services/syncOrchestrator.js
index 0ae6436e4f..e798dda98f 100644
--- a/server/services/syncOrchestrator.js
+++ b/server/services/syncOrchestrator.js
@@ -78,8 +78,10 @@ async function fetchPeer(peer, path) {
* avatarPath is like "/data/images/uuid.png"
*/
async function syncImageFromPeer(peer, avatarPath) {
+ // Validate avatarPath is a safe relative image path under /data/images/
+ if (!avatarPath || avatarPath.includes('..') || !avatarPath.startsWith('/data/images/')) return;
const filename = avatarPath.split('/').pop();
- if (!filename) return;
+ if (!filename || !/\.(png|jpg|jpeg|gif|webp|svg)$/i.test(filename)) return;
const localPath = join(PATHS.images, filename);
// Skip if we already have it
diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.js
index c0005636ab..4b074a64f3 100644
--- a/server/services/worktreeManager.js
+++ b/server/services/worktreeManager.js
@@ -359,12 +359,16 @@ async function cleanupExternalRepoWorktrees(activeAgentIds, alreadyHandled) {
const gitFile = join(worktreePath, '.git');
// Read .git file to find the parent repo
- const gitContent = await readFile(gitFile, 'utf-8').catch(() => null);
+ // In a worktree, .git is a file containing "gitdir: ..."; in a normal repo it's a directory
+ const gitStat = await stat(gitFile).catch(() => null);
+ if (gitStat?.isDirectory()) {
+ // This is a normal git repo, not a worktree — skip to avoid accidental data loss
+ continue;
+ }
+ const gitContent = gitStat ? await readFile(gitFile, 'utf-8').catch(() => null) : null;
if (!gitContent?.startsWith('gitdir:')) {
- // Not a valid worktree — just remove the directory
- console.log(`🌳 Removing invalid worktree directory ${agentId}`);
- await rm(worktreePath, { recursive: true, force: true }).catch(() => {});
- cleaned++;
+ // No .git file or unreadable — skip rather than removing potentially valuable data
+ console.log(`🌳 Skipping worktree directory ${agentId} — cannot determine parent repo`);
continue;
}