Skip to content

fix(mcp): constrain roots workspace upgrades to project scope - #83

Closed
study8677 wants to merge 1 commit into
mainfrom
codex/fix-mcp-client-workspace-re-scoping-vulnerability
Closed

fix(mcp): constrain roots workspace upgrades to project scope#83
study8677 wants to merge 1 commit into
mainfrom
codex/fix-mcp-client-workspace-re-scoping-vulnerability

Conversation

@study8677

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a malicious or compromised MCP client from re-scoping the server process workspace to arbitrary filesystem locations, which could expand read/search scope and leak sensitive files or influence settings reloads.
  • Apply a minimal, conservative safeguard so MCP-root upgrades remain backward-compatible for honest clients while restoring confinement to the operator-chosen project boundary.

Description

  • Add _is_within_workspace(candidate, workspace) to test that a candidate root is the same as or a descendant of the original workspace.
  • Require MCP-supplied roots to be an existing directory and reject roots that are outside the originally resolved _active_workspace before applying the upgrade.
  • Preserve existing behavior for in-scope roots and for clients that do not support roots by keeping the previous workspace and continuing to call reset_settings() on successful in-scope upgrades.

Testing

  • Ran pytest -q, which failed during test collection in this environment due to ModuleNotFoundError: No module named 'ag_cli' (environment import issue unrelated to the change).
  • Ran pytest -q engine/tests/test_mcp_server_errors.py, which produced 5 passed and 1 failed due to the test environment lacking an async pytest plugin (pytest.mark.asyncio unsupported), indicating the modified code exercised without regressions in the remaining assertions.
  • Observed no new exceptions from the modified code path during local test runs; the change is intentionally minimal to limit behavioral surface while restoring confinement.

Codex Task

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant