{"record":{"id":"b928d1981b6cee88","repo":"BerriAI/litellm","slug":"invalid-file-path-file-path-r-path-traversal-de","errorCode":null,"errorMessage":"Invalid file path {file_path!r}: path traversal detected","messagePattern":"Invalid file path (.+?): path traversal detected","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/bitbucket/bitbucket_client.py","lineNumber":19,"sourceCode":"\"\"\"\nBitBucket API client for fetching .prompt files from BitBucket repositories.\n\"\"\"\n\nimport base64\nimport urllib.parse\nfrom typing import Any, Final\n\nfrom litellm.llms.custom_httpx.http_handler import HTTPHandler\n\n\ndef _sanitize_file_path(file_path: str) -> str:\n    \"\"\"Reject path traversal and URL-encode each path segment.\"\"\"\n    if \"#\" in file_path or \"?\" in file_path:\n        raise ValueError(f\"Invalid file path {file_path!r}: contains URL special characters\")\n    parts: Final = file_path.split(\"/\")\n    for part in parts:\n        if part == \"..\":\n            raise ValueError(f\"Invalid file path {file_path!r}: path traversal detected\")\n    return \"/\".join(urllib.parse.quote(part, safe=\"\") for part in parts)\n\n\nclass BitBucketClient:\n    \"\"\"\n    Client for interacting with BitBucket API to fetch .prompt files.\n\n    Supports:\n    - Authentication with access tokens\n    - Fetching file contents from repositories\n    - Team-based access control through BitBucket permissions\n    - Branch-specific file fetching\n    \"\"\"\n\n    def __init__(self, config: dict[str, Any]):\n        \"\"\"\n        Initialize the BitBucket client.\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/bitbucket/bitbucket_client.py#L1-L37","documentation":"_sanitize_file_path splits the path on '/' and raises if any segment equals '..', blocking path traversal before the BitBucket src URL is built. Repository paths are already repo-relative, so a parent-directory reference can never be legitimate — it is either an attack attempt or a client bug building paths with relative navigation.","triggerScenarios":"Passing '../secrets/credentials.prompt' or 'a/../../b.prompt' to get_file_content/list_files; templating code that joins user input with '..' segments; prompts whose names were derived from filesystem-relative logic; adversarial input probing the integration.","commonSituations":"Path built by os.path.join or normpath on the caller side retaining '..'; user-uploaded prompt manifests with relative paths; security testing flagging the guard.","solutions":["Build paths from the repository root: 'prompts/x.prompt' not '../prompts/x.prompt'","Normalize caller-side with posixpath.normpath then re-verify no '..' remains before calling","Reject or clean user-supplied path fields at your API boundary instead of relying on this deep guard"],"exampleFix":"// before\nclient.get_file_content(\"../shared/prompts/triage.prompt\")\n// after\nclient.get_file_content(\"shared/prompts/triage.prompt\")","handlingStrategy":"validation","validationCode":"import posixpath\n\ndef to_repo_path(raw: str) -> str:\n    normalized = posixpath.normpath(raw.strip().lstrip(\"/\"))\n    if normalized.startswith(\"..\") or \"/..\" in normalized:\n        raise ValueError(f\"path escapes repository root: {raw!r}\")\n    return normalized\n\nsafe = to_repo_path(user_supplied_path)","typeGuard":"def is_repo_relative(p: str) -> bool:\n    parts = p.split(\"/\")\n    return bool(p) and \"..\" not in parts and not p.startswith(\"/\")","tryCatchPattern":null,"preventionTips":["Always build paths from the repository root, not relative to the calling file","Normalize caller-side with posixpath.normpath and reject residual '..'","Treat any '..' in user-supplied prompt paths as hostile input at your API boundary","Remember repo-relative paths never legitimately need parent segments"],"tags":["bitbucket","path-traversal","security","input-sanitization"],"backgroundTag":"path-traversal-blocked","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}