fix(cua): scrub operator environment before launching cua-driver MCP (#37878) - #48423
Conversation
- Use _sanitize_subprocess_env() to filter Hermes-managed credentials from the cua-driver subprocess environment (issue #37878) - Prevents credential exfiltration to the third-party cua-driver binary - Aligns with existing pattern used by browser-tool and other tools - Add regression test to verify environment sanitization The cua-driver is a lower-trust MCP subprocess per SECURITY.md §2.3. Its inherited environment is now scrubbed by default, removing provider API keys, gateway tokens, and platform credentials that should not leak to third-party binaries. Fixes #37878
…d ANTHROPIC_API_KEY test Review feedback from egilewski: 1. Remove trailing whitespace from test docstring and mock patches (lines 1430, 1469, 1476, 1482) 2. Expand test coverage: also verify ANTHROPIC_API_KEY is stripped (not just OPENAI_API_KEY) Changes: - Remove trailing whitespace from test file - Add ANTHROPIC_API_KEY to test environment - Add assertion verifying ANTHROPIC_API_KEY is stripped from cua-driver subprocess env - Syntax verified: python3 -m py_compile tests/tools/test_computer_use.py ✓
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
run_agent.py:2941: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
Unchanged: 5768 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
egilewski
left a comment
There was a problem hiding this comment.
looks mergeable
I verified the cua-driver MCP launch no longer inherits Hermes-managed credentials from the operator process. On current main, a synthetic _CuaDriverSession._aenter() capture passed provider keys and gateway/tool tokens through to StdioServerParameters; on this head, the same capture strips those values via _sanitize_subprocess_env() while preserving runtime variables such as PATH and HOME.
Focused validation passed:
/home/mac/hermes-agent/.venv/bin/python -B -m pytest -p no:cacheprovider tests/tools/test_computer_use.py::TestCuaEnvironmentScrubbing::test_cua_session_sanitizes_provider_env_vars tests/test_subprocess_home_isolation.py -q
# 22 passed in 0.88s
coderabbit review --plain --base upstream/main --type committed
# Review complete; no findings
Signed: GPT-5.5-xhigh in Codex
Summary
The
cua-driverMCP subprocess no longer inherits the operator's Hermes-managed credentials.Previously
_CuaDriverSession._aenter()launched the third-partycua-driverbinary withenv={**os.environ}, handing it every provider API key, gateway authorization value, and platform token in the parent process — bypassing the documented MCP subprocess trust boundary (SECURITY.md §2.3) with no prompt injection or break-glass flag required (#37878).Changes
tools/computer_use/cua_backend.py: build the launch env through the existingtools.environments.local._sanitize_subprocess_envhelper (the same onebrowser_toolalready uses for this boundary) instead of passing the raw parent environment.tests/tools/test_computer_use.py: regression test assertingcua-driverlaunch env excludes Hermes-managed credentials while preserving runtime vars.Validation
OPENAI_API_KEYin subprocess envANTHROPIC_API_KEY/OPENROUTER_API_KEY/TELEGRAM_BOT_TOKENPATH/HOME/DISPLAYE2E verified against
_sanitize_subprocess_envwith a populated credential env: all four credentials removed, runtime vars retained. Regression test passes.Salvaged from #41394 by @iamlukethedev (commits cherry-picked, authorship preserved). Closes #37878.
Infographic