{"record":{"id":"9a2cf1bdba3b6bc0","repo":"modelcontextprotocol/servers","slug":"invalid-start-timestamp-start-timestamp-ca","errorCode":null,"errorMessage":"Invalid start_timestamp: '${start_timestamp}' - cannot start with '-'","messagePattern":"Invalid start_timestamp: '(.+?)' - cannot start with '-'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/git/src/mcp_server_git/server.py","lineNumber":162,"sourceCode":"                raise ValueError(f\"Invalid path: '{f}'\")\n            try:\n                resolved.relative_to(repo_root)\n            except ValueError:\n                raise ValueError(\n                    f\"Path '{f}' is outside the repository '{repo_root}'\"\n                )\n        # Use '--' to prevent files starting with '-' from being interpreted as options\n        repo.git.add(\"--\", *files)\n    return \"Files staged successfully\"\n\ndef git_reset(repo: git.Repo) -> str:\n    repo.index.reset()\n    return \"All staged changes reset\"\n\ndef git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str] = None, end_timestamp: Optional[str] = None) -> list[str]:\n    # Defense in depth: reject timestamps starting with '-' to prevent flag injection\n    if start_timestamp and start_timestamp.startswith(\"-\"):\n        raise ValueError(f\"Invalid start_timestamp: '{start_timestamp}' - cannot start with '-'\")\n    if end_timestamp and end_timestamp.startswith(\"-\"):\n        raise ValueError(f\"Invalid end_timestamp: '{end_timestamp}' - cannot start with '-'\")\n\n    kwargs: dict[str, Any] = {\"max_count\": max_count}\n    if start_timestamp:\n        kwargs[\"since\"] = start_timestamp\n    if end_timestamp:\n        kwargs[\"until\"] = end_timestamp\n\n    commits = list(repo.iter_commits(**kwargs))\n    log = []\n    for commit in commits:\n        log.append(\n            f\"Commit: {commit.hexsha}\\n\"\n            f\"Author: {commit.author}\\n\"\n            f\"Date: {commit.authored_datetime}\\n\"\n            f\"Message: {commit.message}\\n\"\n        )","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/d73f99efbfd40c3aa1b61e88728b3d49fb52608f/src/git/src/mcp_server_git/server.py#L144-L180","documentation":"git_log() defends against git flag injection: a start_timestamp beginning with '-' would be interpreted by the git CLI as an option rather than a date (e.g. '--all' or an exec-like char sequence). The function raises ValueError before ever invoking Git when the value starts with a dash.","triggerScenarios":"Calling the git_log tool with arguments like start_timestamp='--since-as-filter' or any LLM-supplied string starting with '-'; passing negative-looking dates such as '-1 day' directly instead of using the supported format.","commonSituations":"LLM clients hallucinating flag-style arguments; users attempting relative dates like '-2 weeks'; adversarial prompt-injection payloads trying to smuggle extra git options through the timestamp parameters.","solutions":["Pass an absolute date/time string that does not begin with '-', e.g. '2024-01-01' or '2 weeks ago'.","Use positive relative expressions ('2 weeks ago') instead of negative ones ('-2 weeks').","Sanitize/strip leading dashes from user-supplied timestamps in your client before calling the tool.","Catch the ValueError in call_tool and return an explanatory message to the model."],"exampleFix":"// before\nawait call_git_log({ \"start_timestamp\": \"-2 weeks\" });\n// after\nawait call_git_log({ \"start_timestamp\": \"2 weeks ago\" });","handlingStrategy":"validation","validationCode":"def safe_timestamp(ts: str | None) -> str | None:\n    if ts and ts.startswith(\"-\"):\n        raise ValueError(f\"timestamp cannot start with '-': {ts}\")\n    return ts\n\nstart_timestamp = safe_timestamp(start_timestamp)","typeGuard":"def is_safe_timestamp(ts: str | None) -> bool:\n    return ts is None or not ts.startswith(\"-\")","tryCatchPattern":"try:\n    log = await call_tool(\"git_log\", {\"repo_path\": path, \"start_timestamp\": ts})\nexcept ValueError as e:\n    if \"cannot start with\" in str(e):\n        return f\"Invalid timestamp, use e.g. '2024-01-01' or '2 weeks ago': {e}\"\n    raise","preventionTips":["Never pass user/LLM strings starting with '-' as git_log timestamp arguments.","Constrain clients to a fixed date format (ISO 8601) with server-side regex validation.","Treat dash-prefixed values as injection attempts and log them."],"tags":["git","flag-injection","security","python"],"backgroundTag":"invalid-argument-value","analyzedSha":"d73f99efbfd40c3aa1b61e88728b3d49fb52608f","analyzedAt":"2026-09-07T14:54:21.545Z","contentChangedAt":"2026-09-07T14:54:21.545Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}