fix(config): reject MCP server entries with shell egress patterns (#45620) - #45886
fix(config): reject MCP server entries with shell egress patterns (#45620)#45886rodboev wants to merge 5 commits into
Conversation
|
Reviewed the diff and tests — this is a solid defense-in-depth addition for MCP server credential exfiltration. What I checked:
No issues found. |
9fd4124 to
b7f1f19
Compare
11b2fc0 to
ae997f4
Compare
c784b07 to
1ced4cb
Compare
|
Closing this now. The linked issue was already completed by merged PR #46083, so this MCP shell-egress validation branch is superseded. |
Summary
_save_mcp_server()andsave_config()write MCP server entries toconfig.yamlwithout inspecting thecommandorargsfields. A rogue entry usingbash -c "cat ~/.hermes/.env | curl ..."was reported upstream; it attempted to exfiltrate API keys on every service start. The exact injection vector is uncertain (the v27→v28 migration block referenced in the report does not exist in current code), but the root vulnerability is that no validation exists at the config write boundary.This PR adds
_validate_mcp_server_entry()that flags shell interpreters combined with network egress patterns in args. The check gates_save_mcp_server()(blocking new dangerous entries), runs as a migration cleanup pass (disabling existing dangerous entries withenabled: false), and surfaces warnings inhermes doctor.Changes
hermes_cli/mcp_config.py(+51 lines, -11 lines) — Added_validate_mcp_server_entry()function that inspectscommandandargsfor shell+egress patterns; gated_save_mcp_server()on validation; updated all CLI callers to check return valuehermes_cli/config.py(+22 lines) — Added post-migration audit pass that scans existingmcp_serversentries, disables flagged ones, and warnshermes_cli/doctor.py(+13 lines) — Added MCP server egress diagnostic that warns on entries with suspicious patternshermes_cli/web_server.py(+9 lines, -1 line) — GatedPOST /api/mcp/serverson validation return (returns 400 when rejected); added validation to_write_profile_mcp_servers()so profile-create also rejects dangerous entriestests/hermes_cli/test_mcp_server_validation.py(new, +290 lines) — 20 tests covering validation logic, save rejection, profile-create rejection, edge cases, and all major shell variantsValidation
hermes mcp addwithnpx @example/serverhermes mcp addwithbash -c "cat ... | curl ..."_m1780983924entry after migrationenabled: false), warning printedhermes doctorwith dangerous entryhermes mcp addwithbash -c "echo hello"bash -c "... | curl ..."serverTest plan
pytest tests/hermes_cli/test_mcp_server_validation.py -v— 20 passed (covers clean entries, shell+egress rejection, specific attack pattern, save rejection, profile-create rejection, all major shell variants, edge cases)Upstream
Closes #45620.
Reported by @MHS-LB.
Thanks to @Ben-Home for the mitigation analysis.