{"record":{"id":"774cdffb3e1921f3","repo":"modelcontextprotocol/servers","slug":"invalid-revision-revision-cannot-start-with","errorCode":null,"errorMessage":"Invalid revision: '{revision}' - cannot start with '-'","messagePattern":"Invalid revision: '(.+?)' - cannot start with '-'","errorType":"validation","errorClass":"BadName","httpStatus":null,"severity":"error","filePath":"src/git/src/mcp_server_git/server.py","lineNumber":229,"sourceCode":"    repo.create_head(branch_name, base)\n    return f\"Created branch '{branch_name}' from '{base.name}'\"\n\ndef git_checkout(repo: git.Repo, branch_name: str) -> str:\n    # Defense in depth: reject branch names starting with '-' to prevent flag injection,\n    # even if a malicious ref with that name exists (e.g. via filesystem manipulation)\n    if branch_name.startswith(\"-\"):\n        raise BadName(f\"Invalid branch name: '{branch_name}' - cannot start with '-'\")\n    repo.rev_parse(branch_name)  # Validates branch_name is a real git ref, throws BadName if not\n    repo.git.checkout(branch_name)\n    return f\"Switched to branch '{branch_name}'\"\n\n\n\ndef git_show(repo: git.Repo, revision: str) -> str:\n    # Defense in depth: reject revisions starting with '-' to prevent flag injection,\n    # even if a malicious ref with that name exists (e.g. via filesystem manipulation)\n    if revision.startswith(\"-\"):\n        raise BadName(f\"Invalid revision: '{revision}' - cannot start with '-'\")\n    commit = repo.commit(revision)\n    output = [\n        f\"Commit: {commit.hexsha!r}\\n\"\n        f\"Author: {commit.author!r}\\n\"\n        f\"Date: {commit.authored_datetime!r}\\n\"\n        f\"Message: {commit.message!r}\\n\"\n    ]\n    if commit.parents:\n        parent = commit.parents[0]\n        diff = parent.diff(commit, create_patch=True)\n    else:\n        diff = commit.diff(git.NULL_TREE, create_patch=True)\n    for d in diff:\n        output.append(f\"\\n--- {d.a_path}\\n+++ {d.b_path}\\n\")\n        if d.diff is None:\n            continue\n        if isinstance(d.diff, bytes):\n            output.append(d.diff.decode('utf-8'))","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/git/src/mcp_server_git/server.py#L211-L247","documentation":"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.","triggerScenarios":"Calling git_show with a revision beginning with '-'; malicious or malformed revision input.","commonSituations":"Adversarial input; malformed SHAs.","solutions":["Reject revisions starting with '-'.","Pass a valid commit SHA, tag, or ref."],"exampleFix":"# before\ngit_show(repo, revision='-sMalicious')  # -> BadName\n\n# after\nif revision.startswith('-'):\n    raise ValueError('revision must not start with -')\ngit_show(repo, revision)","handlingStrategy":"validation","validationCode":"def safe_revision(rev: str) -> str:\n    if not rev or rev.startswith('-'):\n        raise ValueError('revision must not start with -')\n    return rev","typeGuard":null,"tryCatchPattern":"from gitdb.exc import BadName\ntry:\n    git_show(repo, revision)\nexcept BadName as e:\n    if 'cannot start with' in str(e):\n        # sanitize and retry\n    raise","preventionTips":["Reject revisions starting with '-' at the input boundary.","Prefer full commit SHAs or tags over free-form strings."],"tags":["git","python","security","flag-injection","validation"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}