Skip to content

fix(mcp): prevent deletion of protected SystemUtils users - #599

Open
rohanbuilds-ai wants to merge 1 commit into
GenAI-Security-Project:mainfrom
rohanbuilds-ai:fix/systemutils-protected-users
Open

rohanbuilds-ai wants to merge 1 commit into
GenAI-Security-Project:mainfrom
rohanbuilds-ai:fix/systemutils-protected-users

Conversation

@rohanbuilds-ai

Copy link
Copy Markdown

Summary

Fixes #398 by preventing destructive delete actions on reserved administrative accounts (admin, root, system) in the SystemUtils MCP server's manage_users tool.

Root Cause & Reproduction

In finbot/mcp/servers/systemutils/server.py, manage_users accepted arbitrary action and username combinations without validating against protected system accounts. Calling:

manage_users(action="delete", username="admin")

silently succeeded and returned {"status": "completed"}, allowing a compromised or prompt-injected agent to delete the primary platform administrator.

Changes Made

  • Defined PROTECTED_USERNAMES: set[str] = {"admin", "root", "system"} at module level in finbot/mcp/servers/systemutils/server.py.
  • Added a validation guard in manage_users ensuring action.strip().lower() == "delete" raises a ValueError if username.strip().lower() matches any protected name.
  • Non-destructive operations (list, create, modify) on protected accounts and deletion of standard user accounts continue to work as expected.

Verification & Acceptance

Added 17 unit tests in tests/unit/mcp/test_systemutils.py:

  • test_su_usr_001_returns_expected_fields: Valid user operations return expected dictionary structure.
  • test_su_usr_002_delete_admin_rejected_as_protected: Deleting admin is rejected as protected.
  • test_su_usr_002_delete_admin_accepted_without_validation: Acceptance alias confirming the issue's named test passes.
  • Parameterized case-insensitivity and whitespace tests across all protected accounts (admin, root, system).
  • Deleting non-protected accounts succeeds.
  • Non-delete operations (list, create, modify) on admin succeed.

Test Results

  • uv run pytest tests/unit/mcp/ -q: 17 passed in 2.24s.
  • uv run pytest tests/unit/mcp/test_systemutils.py::TestManageUsers::test_su_usr_002_delete_admin_accepted_without_validation -v: 1 passed in 0.28s.
  • uv run isort --check-only finbot/mcp/servers/systemutils/server.py tests/unit/mcp/test_systemutils.py: Clean.
  • uv run black --check finbot/mcp/servers/systemutils/server.py tests/unit/mcp/test_systemutils.py: Clean.
  • git diff --check: Clean (0 whitespace warnings).

Block destructive 'delete' operations on reserved system usernames (admin, root, system) in SystemUtils manage_users.

- Define PROTECTED_USERNAMES set containing 'admin', 'root', and 'system'.
- Validate case-insensitively and whitespace-trimmed in manage_users before processing delete actions.
- Allow non-delete actions (list, create, modify) on protected accounts and delete actions on standard user accounts.
- Add comprehensive test coverage in tests/unit/mcp/test_systemutils.py.

Fixes GenAI-Security-Project#398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug_177_EVALUATE: SU-USR-002 — Deleting admin user accepted without validation in manage_users

1 participant