Resolve #604 Running mcp-server-git with uvx gives full disk access/--repository param is ignored #630
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.
Description
Security Enhancement: Robust Path Validation and Parent Directory Support
Key Improvements
server.py
)New
PathValidator
Class:/etc
,/usr
, etc.)..
)--repository
) is configured, all paths are contained within itDual-Mode Validation:
repo_path
repo_path
that is validated against the base directoryServer Initialization Improvements (
__init__.py
)Tool Access Control & Error Handling (
server.py
)PathValidator
git_status
,git_diff
,git_create_branch
, etc., dynamically adjust their input schema based on the current configuration modeDocumentation Updates (
README.md
)../
traversal, system directory protection)start_point
tobase_branch
in branch creation)Enhanced Testing (
test_server.py
)Motivation and Context
This change is necessary to ensure that the Git MCP server is not vulnerable to malicious path traversal or unintended access to critical system directories. In addition to improving security:
How Has This Been Tested?
test_server.py
covering safe/unsafe path checks, repository validation, and tool operationsBreaking Changes
--repository
flag points to a parent directory (instead of a single Git repository), clients must provide an explicitrepo_path
with each tool call.Types of Changes
Checklist
Additional Context
Defense-in-Depth Approach:
Tool Dispatch Adjustments:
Adjusts the schema and parameters on the fly based on whether the base directory is a single repository or a parent directory containing multiple repositories.
Security Impact:
This PR significantly improves the server's security posture by ensuring:
Resolves #604