modelcontextprotocol/servers · error · BadName
Invalid revision: '{revision}' - cannot start with '-'
Error message
Invalid revision: '{revision}' - cannot start with '-' What it means
git_show() rejects a revision that starts with '-' to prevent flag injection into `git show`/commit lookup. The check fires before repo.commit(revision). Raises gitdb BadName; propagates raw to the MCP client.
Source
Thrown at src/git/src/mcp_server_git/server.py:229
repo.create_head(branch_name, base)
return f"Created branch '{branch_name}' from '{base.name}'"
def git_checkout(repo: git.Repo, branch_name: str) -> str:
# Defense in depth: reject branch names starting with '-' to prevent flag injection,
# even if a malicious ref with that name exists (e.g. via filesystem manipulation)
if branch_name.startswith("-"):
raise BadName(f"Invalid branch name: '{branch_name}' - cannot start with '-'")
repo.rev_parse(branch_name) # Validates branch_name is a real git ref, throws BadName if not
repo.git.checkout(branch_name)
return f"Switched to branch '{branch_name}'"
def git_show(repo: git.Repo, revision: str) -> str:
# Defense in depth: reject revisions starting with '-' to prevent flag injection,
# even if a malicious ref with that name exists (e.g. via filesystem manipulation)
if revision.startswith("-"):
raise BadName(f"Invalid revision: '{revision}' - cannot start with '-'")
commit = repo.commit(revision)
output = [
f"Commit: {commit.hexsha!r}\n"
f"Author: {commit.author!r}\n"
f"Date: {commit.authored_datetime!r}\n"
f"Message: {commit.message!r}\n"
]
if commit.parents:
parent = commit.parents[0]
diff = parent.diff(commit, create_patch=True)
else:
diff = commit.diff(git.NULL_TREE, create_patch=True)
for d in diff:
output.append(f"\n--- {d.a_path}\n+++ {d.b_path}\n")
if d.diff is None:
continue
if isinstance(d.diff, bytes):
output.append(d.diff.decode('utf-8'))View on GitHub (pinned to 76d64c822f)
Solutions
- Reject revisions starting with '-'.
- Pass a valid commit SHA, tag, or ref.
Example fix
# before
git_show(repo, revision='-sMalicious') # -> BadName
# after
if revision.startswith('-'):
raise ValueError('revision must not start with -')
git_show(repo, revision) Defensive patterns
Strategy: validation
Validate before calling
def safe_revision(rev: str) -> str:
if not rev or rev.startswith('-'):
raise ValueError('revision must not start with -')
return rev Try / catch
from gitdb.exc import BadName
try:
git_show(repo, revision)
except BadName as e:
if 'cannot start with' in str(e):
# sanitize and retry
raise Prevention
- Reject revisions starting with '-' at the input boundary.
- Prefer full commit SHAs or tags over free-form strings.
When it happens
Trigger: Calling git_show with a revision beginning with '-'; malicious or malformed revision input.
Common situations: Adversarial input; malformed SHAs.
Related errors
- Invalid target: '{target}' - cannot start with '-'
- Invalid start_timestamp: '{start_timestamp}' - cannot start
- Invalid end_timestamp: '{end_timestamp}' - cannot start with
- Invalid branch name: '{branch_name}' - cannot start with '-'
- Invalid base branch: '{base_branch}' - cannot start with '-'
AI-assisted analysis of modelcontextprotocol/servers@76d64c822f (2026-08-12).
Data as JSON: /api/errors/774cdffb3e1921f3.
Report an issue: GitHub.