mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-17 21:54:05 +02:00
git: improve file path validation in add operation
Add validation to ensure file paths are within repository boundaries before staging. This prevents potential issues with relative paths and improves overall robustness of the git_add function.
This commit is contained in:
@@ -132,6 +132,14 @@ def git_add(repo: git.Repo, files: list[str]) -> str:
|
||||
if files == ["."]:
|
||||
repo.git.add(".")
|
||||
else:
|
||||
# Validate paths are within repository before adding
|
||||
for file in files:
|
||||
try:
|
||||
repo.git.check_attr('-a', file)
|
||||
except git.exc.GitCommandError as e:
|
||||
if 'outside repository' in str(e):
|
||||
raise ValueError(f"Path '{file}' is outside repository")
|
||||
raise
|
||||
repo.index.add(files)
|
||||
return "Files staged successfully"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user