fix(api): add DNS rebinding protection via Host header validation#124
Conversation
|
@fanhongy Good security fix — DNS rebinding is a real risk for localhost services like CAO, and Items to fix1. Code Quality CI is failing — uv run black src/cli_agent_orchestrator/constants.py test/api/test_security.py2. IPv6 tests are skipped — Both |
|
Right. removed ipv6 from |
Thanks again for the quick turnaround @fanhongy . Some suggestions (minor) below : 1. Add a note to Users who expose the server ( The server validates HTTP `Host` headers to prevent [DNS rebinding attacks](https://owasp.org/www-community/attacks/DNS_Rebinding).
Only `localhost` and `127.0.0.1` are accepted by default — requests with other hostnames are rejected with `400 Bad Request`.2. Add a comment in The allowed hosts list is currently hardcoded, which is correct for now. But please add a comment noting the intended extension point so future maintainers know where to add CLI/env # Allowed Host headers for DNS rebinding protection (CVE mitigation)
# Only localhost connections permitted - CAO is a local-only service
# These hosts are validated by TrustedHostMiddleware to prevent DNS rebinding attacks
# Note: IPv6 (::1) is not included as CAO is accessed via IPv4 localhost in practice
# To allow additional hosts in the future, add a --allowed-hosts CLI flag
# or CAO_ALLOWED_HOSTS env var (comma-separated).
ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
]Rest LGTM, much appreciated again~ |
|
added to README.md with a bit statement and comment on the |
Bring the event-driven architecture branch up to date with main (98 commits) and reconcile the rewrite with features that landed after it forked: eager inbox delivery (awslabs#251), the OpenCode poller, env-var forwarding (awslabs#259), memory curation (awslabs#254/awslabs#262), CORS auto-derive (awslabs#261), DNS host validation (awslabs#124), and the self-send guard (awslabs#24). Highlights: - Providers adopt the async initialize() + get_status(buffer) contract; copilot_cli/opencode_cli converted; kiro keeps colour-only ANSI stripping so carriage-return-redraw permission prompts aren't misread as idle. - Event-driven InboxService.deliver_pending with the awslabs#251 eager gate and message-sender attribution; OpenCode poller retained as a status-driven method; the watchdog (PollingObserver/LogFileHandler) is removed. - terminal_service.create_terminal is async (FIFO + StatusMonitor wiring); session_service.create_session, flow_service.execute_flow, the API endpoints, and `cao flow run` updated to await. - memory_service curated path and the flow CLI fixed to the new contract. Full unit suite green (1908 passed); black + isort clean.
🔒 Security Fix: DNS Rebinding Protection (CVE Mitigation)
Severity: HIGH (CVSS 8.1)
Type: DNS Rebinding Attack / Command Injection
Status: FIXED
Summary
Adds DNS rebinding protection to the CAO server by implementing Host header validation via FastAPI's
TrustedHostMiddleware. Without this fix, malicious websites could exploit DNS rebinding to send arbitrary prompts to running CAO agents, potentially executing commands, reading sensitive files, or exfiltrating credentials.Vulnerability Description
CAO server did not validate the
Hostheader in incoming HTTP requests. This allowed DNS rebinding attacks where:attack.poc)attack.poc→127.0.0.1(short TTL)attack.poc(same-origin)localhost:9889(CAO server)Attack Vector: Network (requires user to visit malicious site)
Impact: Command execution, data exfiltration, credential theft
Changes Made
src/cli_agent_orchestrator/constants.pyALLOWED_HOSTS(localhost, 127.0.0.1, ::1)src/cli_agent_orchestrator/api/main.pyTrustedHostMiddlewaretest/api/test_security.pytest/api/conftest.pyTestClientWithHostfixture for middleware compatibilitytest/api/test_terminals.pytest/api/test_inbox_messages.pyNet Addition: ~350 lines (mostly security tests)
Testing
✅ Legitimate requests (
localhost,127.0.0.1) → 200 OK❌ Attack requests (
attack.poc,malicious-site.com) → 400 Bad RequestNo Breaking Changes
Normal CAO usage (server, CLI, MCP connections, browser access on localhost) is completely unaffected.
References
AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N(Score: 8.1 HIGH)