Repository navigation
fix(mcp): prevent deletion of protected SystemUtils users - #599
Open
rohanbuilds-ai wants to merge 1 commit into
Open
rohanbuilds-ai wants to merge 1 commit into
rohanbuilds-ai wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #398 by preventing destructive
deleteactions on reserved administrative accounts (admin,root,system) in the SystemUtils MCP server'smanage_userstool.Root Cause & Reproduction
In
finbot/mcp/servers/systemutils/server.py,manage_usersaccepted arbitraryactionandusernamecombinations without validating against protected system accounts. Calling:silently succeeded and returned
{"status": "completed"}, allowing a compromised or prompt-injected agent to delete the primary platform administrator.Changes Made
PROTECTED_USERNAMES: set[str] = {"admin", "root", "system"}at module level infinbot/mcp/servers/systemutils/server.py.manage_usersensuringaction.strip().lower() == "delete"raises aValueErrorifusername.strip().lower()matches any protected name.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: Deletingadminis rejected as protected.test_su_usr_002_delete_admin_accepted_without_validation: Acceptance alias confirming the issue's named test passes.admin,root,system).list,create,modify) onadminsucceed.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).