-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
fix(security): harden dashboard-web — loopback-only bind + Host/Origin guard (#2506) #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Rule Used: Treat CLI inputs, URLs, file paths, and subprocess... (source)
Comment on lines
+24
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -n "ECC_DASHBOARD_HOST|server\.listen|server\.on\(['\"]error" scripts/dashboard-web.jsRepository: affaan-m/ECC Length of output: 253 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,120p' scripts/dashboard-web.js
printf '\n---\n'
sed -n '730,800p' scripts/dashboard-web.jsRepository: affaan-m/ECC Length of output: 19793 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,240p' scripts/lib/loopback-guard.jsRepository: affaan-m/ECC Length of output: 1816 Validate
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| 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`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| 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 */ } | ||
| }); | ||
|
Comment on lines
+773
to
776
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
ECC_DASHBOARD_HOST=0.0.0.0is used for the documented LAN/container access case, this allowlist only includes loopback names plus the literal0.0.0.0. A browser connecting via the machine or container address sends a Host header such as192.168.1.10:3456orhost.docker.internal:3456, so the new guard returns 421 and the dashboard is unusable unless the client spoofs Host. Separate the bind address from the accepted public hostnames, or provide an explicit allowed-hosts setting for non-loopback binds.Useful? React with 👍 / 👎.