Skip to content

fix(cua): scrub operator environment before launching cua-driver MCP (#37878) - #48423

Merged
teknium1 merged 3 commits into
mainfrom
fix/37878-cua-env-scrub
Jun 18, 2026
Merged

fix(cua): scrub operator environment before launching cua-driver MCP (#37878)#48423
teknium1 merged 3 commits into
mainfrom
fix/37878-cua-env-scrub

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

The cua-driver MCP subprocess no longer inherits the operator's Hermes-managed credentials.

Previously _CuaDriverSession._aenter() launched the third-party cua-driver binary with env={**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 existing tools.environments.local._sanitize_subprocess_env helper (the same one browser_tool already uses for this boundary) instead of passing the raw parent environment.
  • tests/tools/test_computer_use.py: regression test asserting cua-driver launch env excludes Hermes-managed credentials while preserving runtime vars.

Validation

Before After
OPENAI_API_KEY in subprocess env present stripped
ANTHROPIC_API_KEY / OPENROUTER_API_KEY / TELEGRAM_BOT_TOKEN present stripped
PATH / HOME / DISPLAY present preserved

E2E verified against _sanitize_subprocess_env with 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

scrub-the-env

- 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 ✓
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/37878-cua-env-scrub vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11009 on HEAD, 11011 on base (✅ -2)

🆕 New issues (1):

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.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening comp/tools Tool registry, model_tools, toolsets P0 Critical — data loss, security, crash loop labels Jun 18, 2026

@egilewski egilewski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P0 Critical — data loss, security, crash loop type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cua): scrub operator environment before launching cua-driver MCP

5 participants