From 8c96b953c20cabdcd14fcf1c8ef1e2b1d3357f15 Mon Sep 17 00:00:00 2001 From: Pangerkumzuk Longkumer <73515951+pangerlkr@users.noreply.github.com> Date: Tue, 14 Jul 2026 10:34:54 +0530 Subject: [PATCH 1/2] =?UTF-8?q?fix(#2506):=20harden=20dashboard-web=20?= =?UTF-8?q?=E2=80=94=20loopback-only=20bind=20+=20Host/Origin=20guard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes gap 1 from issue #2506. - Bind to process.env.ECC_DASHBOARD_HOST || '127.0.0.1' instead of all interfaces (0.0.0.0/::/default) - Wire loopback-guard.js: reject requests with a disallowed Host header (421) to block DNS-rebinding attacks - Wire loopback-guard.js: reject cross-origin requests with a disallowed Origin header (403) - Pass HOST to server.listen() so the bind address matches the guard allowlist Gap 2 (agent-data-home path containment) will follow in a separate commit. --- scripts/dashboard-web.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/dashboard-web.js b/scripts/dashboard-web.js index 12094fbcfbb..a194110234b 100644 --- a/scripts/dashboard-web.js +++ b/scripts/dashboard-web.js @@ -12,6 +12,7 @@ const fs = require('fs'); const path = require('path'); const http = require('http'); +const { buildAllowedHostnames, isAllowedHostHeader, isAllowedOrigin } = require('./lib/loopback-guard'); function parsePort(v) { const n = parseInt(String(v), 10); @@ -20,6 +21,8 @@ function parsePort(v) { } const PORT = parsePort(process.argv[2] || process.env.ECC_DASHBOARD_PORT || '3456'); const ROOT = path.resolve(__dirname, '..'); +const HOST = process.env.ECC_DASHBOARD_HOST || '127.0.0.1'; +const ALLOWED = buildAllowedHostnames(HOST); function readFrontmatter(p) { try { @@ -756,17 +759,18 @@ handleRoute(); } const server = http.createServer((req, res) => { - const url = new URL(req.url, 'http://localhost'); + if (!isAllowedHostHeader(req.headers['host'], ALLOWED)) { res.writeHead(421, { 'Content-Type': 'text/plain' }); return res.end('421 Misdirected Request'); } if (req.headers['origin'] && !isAllowedOrigin(req.headers['origin'], ALLOWED)) { res.writeHead(403, { 'Content-Type': 'text/plain' }); return res.end('403 Forbidden'); } const url = new URL(req.url, 'http://localhost'); if (url.pathname === '/api/data') { res.writeHead(200, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify({ agents: loadAgents(), skills: loadSkills(), commands: loadCommands(), rules: loadRules(), mcps: loadMcps(), hooks: loadHooks() })); + } res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.end(renderHTML({ agents: loadAgents(), skills: loadSkills(), commands: loadCommands(), rules: loadRules(), mcps: loadMcps(), hooks: loadHooks() })); }); if (require.main === module) { - server.listen(PORT, () => { + server.listen(PORT, HOST, () => { console.log(`\n ECC Capabilities → http://localhost:${PORT}\n`); try { const { spawn } = require('child_process'); const p = process.platform; const c = p === 'darwin' ? 'open' : p === 'win32' ? 'start' : 'xdg-open'; if (c === 'start') spawn('cmd', ['/c', 'start', `http://localhost:${PORT}`], { stdio: 'ignore' }); else spawn(c, [`http://localhost:${PORT}`], { stdio: 'ignore' }); } catch { /* best-effort auto-open */ } }); From 4bf738ad86cf45a1890f2020e393696401896f00 Mon Sep 17 00:00:00 2001 From: Pangerkumzuk Longkumer <73515951+pangerlkr@users.noreply.github.com> Date: Tue, 14 Jul 2026 10:39:17 +0530 Subject: [PATCH 2/2] fix(#2506): enforce path containment in readProjectConfigAt via assertWithinTrustedRoot Fixes gap 2 from issue #2506. readProjectConfigAt() reads agentDataHome from /.cursor/ecc-agent-data.json and passes it through expandHomePath(), but never validated that the resolved path stays within a safe root. An attacker-controlled config file could redirect session-data writes to arbitrary locations via absolute paths or path traversal. This commit: - Imports assertWithinTrustedRoot from path-safety.js (same pattern used elsewhere) - After expandHomePath(), calls assertWithinTrustedRoot(resolved, getHomeDirFromEnv(), 'agent-data-home write') to enforce that any configured path stays within the user home subtree - If the path escapes the trusted root, assertWithinTrustedRoot throws, the surrounding try/catch in readProjectConfigAt returns null (safe fallback), and ECC falls back to its default agent-data-home resolution --- scripts/lib/agent-data-home.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/lib/agent-data-home.js b/scripts/lib/agent-data-home.js index 32da5563a69..58395ed6ccb 100644 --- a/scripts/lib/agent-data-home.js +++ b/scripts/lib/agent-data-home.js @@ -14,6 +14,7 @@ const fs = require('fs'); const path = require('path'); +const { assertWithinTrustedRoot } = require('./path-safety'); const AGENT_DATA_HOME_ENV = 'ECC_AGENT_DATA_HOME'; const DEFAULT_CLAUDE_DIR_NAME = '.claude'; @@ -104,7 +105,7 @@ function readProjectConfigAt(configPath) { const candidate = parsed.agentDataHome || parsed.ECC_AGENT_DATA_HOME; if (typeof candidate !== 'string' || !candidate.trim()) return null; const projectRoot = resolveProjectRootFromConfigPath(configPath); - return expandHomePath(candidate, projectRoot); + const resolved = expandHomePath(candidate, projectRoot); assertWithinTrustedRoot(resolved, getHomeDirFromEnv(), 'agent-data-home write'); return resolved; } catch (error) { console.error( `[ECC] Failed to read or parse agent data config at ${configPath}: ${error.message}`