{"record":{"id":"a6a7774d76a6070e","repo":"modelcontextprotocol/servers","slug":"invalid-path-repo-path","errorCode":null,"errorMessage":"Invalid path: {repo_path}","messagePattern":"Invalid path: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/git/src/mcp_server_git/server.py","lineNumber":262,"sourceCode":"        if d.diff is None:\n            continue\n        if isinstance(d.diff, bytes):\n            output.append(d.diff.decode('utf-8'))\n        else:\n            output.append(d.diff)\n    return \"\".join(output)\n\ndef validate_repo_path(repo_path: Path, allowed_repository: Path | None) -> None:\n    \"\"\"Validate that repo_path is within the allowed repository path.\"\"\"\n    if allowed_repository is None:\n        return  # No restriction configured\n\n    # Resolve both paths to handle symlinks and relative paths\n    try:\n        resolved_repo = repo_path.resolve()\n        resolved_allowed = allowed_repository.resolve()\n    except (OSError, RuntimeError):\n        raise ValueError(f\"Invalid path: {repo_path}\")\n\n    # Check if repo_path is the same as or a subdirectory of allowed_repository\n    try:\n        resolved_repo.relative_to(resolved_allowed)\n    except ValueError:\n        raise ValueError(\n            f\"Repository path '{repo_path}' is outside the allowed repository '{allowed_repository}'\"\n        )\n\n\ndef git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, not_contains: str | None = None) -> str:\n    # Defense in depth: reject values starting with '-' to prevent flag injection\n    if contains and contains.startswith(\"-\"):\n        raise BadName(f\"Invalid contains value: '{contains}' - cannot start with '-'\")\n    if not_contains and not_contains.startswith(\"-\"):\n        raise BadName(f\"Invalid not_contains value: '{not_contains}' - cannot start with '-'\")\n\n    match contains:","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/git/src/mcp_server_git/server.py#L244-L280","documentation":"validate_repo_path() resolves both repo_path and the configured allowed_repository with Path.resolve(); if resolve() raises OSError or RuntimeError (broken symlink, symlink loop, illegal characters, permission error), it is rethrown as ValueError 'Invalid path: ...'. This is the resolve step; the separate outside-repo check produces a different message. validate_repo_path is a no-op when allowed_repository (the server's repository argument) is None.","triggerScenarios":"Client passes a repo_path that is a broken symlink, a loop, or contains illegal characters while an allowed_repository is configured.","commonSituations":"Client supplies a stale or non-existent path; symlinked repo roots whose target is missing; permission issues on the path.","solutions":["Pass a repo_path that is an existing, valid directory resolvable on the server host.","Use a repo_path returned by list_repos() (derived from Roots or the configured repository).","Ensure the allowed_repository itself resolves correctly."],"exampleFix":"# before\nvalidate_repo_path(Path('/tmp/broken-symlink'), allowed_repository=Path('/repo'))  # -> ValueError\n\n# after\np = Path(repo_path)\nif not p.is_dir():\n    raise ValueError('repo_path must be an existing directory')\nvalidate_repo_path(p.resolve(), allowed_repository=Path('/repo'))","handlingStrategy":"validation","validationCode":"from pathlib import Path\ndef valid_repo_path(repo_path: Path, allowed: Path | None) -> None:\n    if allowed is None:\n        return\n    if not repo_path.is_dir():\n        raise ValueError(f'Invalid path: {repo_path}')\n    resolved = repo_path.resolve()\n    if not resolved.is_relative_to(allowed.resolve()):\n        raise ValueError(f'Repository path {repo_path} is outside the allowed repository {allowed}')","typeGuard":null,"tryCatchPattern":"try:\n    validate_repo_path(repo_path, allowed_repository)\nexcept ValueError as e:\n    if e.args[0].startswith('Invalid path:'):\n        # pick a repo_path from list_repos() instead\n    raise","preventionTips":["Pass repo_path values returned by list_repos() rather than user-typed paths.","Ensure the path is an existing, resolvable directory before calling.","Keep the allowed_repository (server repository arg) consistent across calls."],"tags":["git","python","path","validation","symlink"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}