-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Resolve #604 Running mcp-server-git with uvx gives full disk access/--repository param is ignored #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
97be465 to
457e3dc
Compare
2ba16cf to
551777f
Compare
…rovements with latest changes
|
Hi @sparesparrow thanks for opening this, fyi since a lot has changed since your last push I went ahead and:
|
|
This is an important set of changes, so I felt it was worthwhile to ask Copilot for a review of the code against the claims in the description and additional comments: Claims & How the PR Addresses Them1. Security Enhancement: Robust Path Validation and Parent Directory Support
Code evidence:
2. Server Initialization Improvements (
|
cliffhall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I reviewed the code, I'm a Typescript-focused developer, so when I tried to run the unit tests locally, found that there was no documentation in the README about the requirements and procedures to do so.
Made sure to close all file handles and call `test_repo.close()` before deleting test repos for the git server.
…cy test advice. 2) Make the Unit Test insensitive to the git default branch name
…ove legacy test advice." (wrong branch push) This reverts commit b43ecf8.
…cy test advice. 2) Make the Unit Test insensitive to the git default branch name
…otocol/servers into fix/mcp-git-tests
Description
Security Enhancement: Robust Path Validation and Parent Directory Support
Key Improvements
server.py)New
PathValidatorClass:/etc,/usr, etc.)..)--repository) is configured, all paths are contained within itDual-Mode Validation:
repo_pathrepo_paththat is validated against the base directorygraph TD A[Client Request] --> B{--repository flag provided?} B -- Yes --> C[Configured Base Directory Provided] B -- No --> D[Require Explicit repo_path in Tool Call] C --> E{Is Configured Base a Git Repo?} E -- Yes --> F[Automatically use Base Repository] E -- No --> D D --> G[Validate Provided repo_path] G --> H{repo_path within Allowed Base?} H -- Yes --> I[Proceed with Operation] H -- No --> J[Reject Request with Error]Server Initialization Improvements (
__init__.py)Tool Access Control & Error Handling (
server.py)PathValidatorgit_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_pointtobase_branchin 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.pycovering safe/unsafe path checks, repository validation, and tool operationsBreaking Changes
--repositoryflag points to a parent directory (instead of a single Git repository), clients must provide an explicitrepo_pathwith 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