[security] fix(api): require explicit opt-in for agent shell tools#243
Conversation
…KUDS#242 host gate HKUDS#242's _reject_untrusted_loopback_host middleware now 403s loopback requests carrying an attacker-controlled Host before they reach the route. Update the DNS-rebound tests from HKUDS#243 (/swarm/runs, /sessions/messages) and HKUDS#245 (/settings/llm) to assert the request is rejected at the host-gate layer (403) and never reaches the shell-tool / settings-write decision. Full suite: 3217 passed.
Require a valid bearer token (not just loopback peer IP) for settings WRITE endpoints (/settings/llm, /settings/data-sources) when API_AUTH_KEY is configured, closing a DNS-rebinding / loopback-trust bypass while keeping zero-config local dev writes. Also reconciles the DNS-rebound security tests across the #241-#245 sprint: now that #242's rebound-host middleware 403s loopback requests with an attacker-controlled Host before they reach the route, the end-to-end rebound tests for /swarm/runs and /sessions/messages (#243) and /settings/llm (#245) assert the request is rejected at the host-gate layer (403) and never reaches the shell-tool / settings-write decision. Full suite: 3217 passed.
|
Merged, thanks! Dropping request-locality from the shell-tool grant (explicit |
Summary
This PR hardens the API-started agent boundary so shell-capable tools are not enabled solely because a request appears to come from loopback.
VIBE_TRADING_ENABLE_SHELL_TOOLSbefore API-created SWARM workers or session AgentLoop attempts can receivebash/ background shell tools./swarm/runsand/sessions/{session_id}/messages, proving shell tools are not enabled by default.Security issues covered
Before this PR
_shell_tools_enabled_for_request()returned true for any loopback client./swarm/runspassed that value intoruntime.start_run(..., include_shell_tools=...)./sessions/{session_id}/messagespassed that value intosvc.send_message(..., include_shell_tools=...).bashwhen shell tools are enabled.After this PR
VIBE_TRADING_ENABLE_SHELL_TOOLSis explicitly enabled.Host/Originand verifyinclude_shell_tools=Falsefor both SWARM and session message flows.Explicit operator choice
Secure default:
Behavior:
Explicit trusted opt-in:
Behavior:
Why this matters
Shell-capable agent tools execute commands on the host as the API process user. Browser-origin requests can reach local services through localhost and DNS-rebinding patterns, so peer IP alone is not a reliable expression of operator intent.
A safer boundary is an explicit server-side operator opt-in for shell-capable tools.
How this differs from related PRs
bash/ background shell capability to API-started SWARM workers or session AgentLoop attempts.Attack flow
Affected code
agent/api_server.py_shell_tools_enabled_for_request()inferred shell capability from loopback peer IPagent/api_server.py/sessions/{session_id}/messagespassed the request-derived shell-tool flag intoSessionService.send_message()agent/api_server.py/swarm/runspassed the request-derived shell-tool flag into SWARM runtime creationagent/tests/test_security_auth_api.pyRoot cause
CVSS assessment
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:HRationale: a remote attacker needs a victim to visit an attacker-controlled page, but no API key or Vibe-Trading credentials are required. The resulting workflow can expose host command-execution-capable tools in the local API process context.
Safe reproduction steps
Before the fix, a Docker proof using the real FastAPI app, real routes, real session/SWARM services, and a deterministic fake LLM showed:
After this PR, the same session proof no longer exposes
bash, so the marker is not created:Expected vulnerable behavior
On vulnerable code, a rebound loopback request can cause an API-started agent workflow to receive shell tools without
VIBE_TRADING_ENABLE_SHELL_TOOLSbeing set.Changes in this PR
_shell_tools_enabled_for_request()to rely only onVIBE_TRADING_ENABLE_SHELL_TOOLS./swarm/runsrequests getinclude_shell_tools=False/sessions/{session_id}/messagesrequests getinclude_shell_tools=FalseFiles changed
agent/api_server.pyagent/tests/test_security_auth_api.pyMaintainer impact
VIBE_TRADING_ENABLE_SHELL_TOOLS=1.Fix rationale
Host shell tools are a high-impact local capability. They should be gated by explicit server-side configuration so that browser-origin request tricks cannot turn request locality into host command execution capability.
Type of change
Test plan
Local validation:
Result:
Docker validation:
Result:
After-fix Docker proof for the session route:
Disclosure notes
This PR is intentionally bounded to shell-tool exposure for API-started agent workflows. It does not claim to replace Host-header/DNS-rebinding admission hardening; it complements that boundary by requiring explicit operator opt-in before shell-capable tools are exposed to agents started through the API.