{"record":{"id":"8977fd2b37dd32a5","repo":"modelcontextprotocol/servers","slug":"invalid-end-timestamp-end-timestamp-cannot-8977fd","errorCode":null,"errorMessage":"Invalid end_timestamp: '${end_timestamp}' - cannot start with '-'","messagePattern":"Invalid end_timestamp: '(.+?)' - cannot start with '-'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/git/src/mcp_server_git/server.py","lineNumber":164,"sourceCode":"                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        )\n    return log\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/d73f99efbfd40c3aa1b61e88728b3d49fb52608f/src/git/src/mcp_server_git/server.py#L146-L182","documentation":"Companion check to error 3, applied to end_timestamp: a value starting with '-' could be parsed by the underlying git process as a command-line flag instead of the 'until' date, enabling option injection. git_log() rejects it with ValueError before running Git.","triggerScenarios":"Passing end_timestamp values like '--patches' or '-1 day' to the git_log tool; any client (especially LLM-driven) that emits dash-prefixed strings in the end_timestamp argument.","commonSituations":"Relative-date confusion ('-1 week'); prompt-injection attempts smuggling git options; copy-pasted CLI examples where the dash belonged to a flag rather than the date.","solutions":["Provide an absolute date string without a leading dash, e.g. '2024-06-30T23:59:59'.","Express relative windows positively, e.g. end_timestamp='yesterday' or '1 week ago'.","Validate/trim leading '-' characters from end_timestamp in the calling client.","Handle the ValueError gracefully and prompt the user/model for a corrected timestamp."],"exampleFix":"// before\nawait call_git_log({ \"end_timestamp\": \"--until=now\" });\n// after\nawait call_git_log({ \"end_timestamp\": \"now\" });","handlingStrategy":"validation","validationCode":"def safe_end(ts: str | None) -> str | None:\n    if ts and ts.startswith(\"-\"):\n        raise ValueError(f\"end_timestamp cannot start with '-': {ts}\")\n    return ts\n\nend_timestamp = safe_end(end_timestamp)","typeGuard":"def is_safe_end_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, \"end_timestamp\": ts})\nexcept ValueError as e:\n    if \"end_timestamp\" in str(e) or \"cannot start with\" in str(e):\n        return \"Please provide an absolute date like '2024-06-30' instead.\"\n    raise","preventionTips":["Use absolute ISO dates for end_timestamp; express relative windows positively ('1 week ago').","Sanitize both timestamp fields identically in client code before invoking the tool.","Review tool schemas so dash-prefixed values are rejected at the input-validation layer."],"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-14T05:17:10.506Z"}