BerriAI/litellm · error · ValueError
Invalid file path : path traversal detected
Error message
Invalid file path {file_path!r}: path traversal detected What it means
_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.
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
Example fix
// before
client.get_file_content("../shared/prompts/triage.prompt")
// after
client.get_file_content("shared/prompts/triage.prompt") Defensive patterns
Strategy: validation
Validate before calling
import posixpath
def to_repo_path(raw: str) -> str:
normalized = posixpath.normpath(raw.strip().lstrip("/"))
if normalized.startswith("..") or "/.." in normalized:
raise ValueError(f"path escapes repository root: {raw!r}")
return normalized
safe = to_repo_path(user_supplied_path) Type guard
def is_repo_relative(p: str) -> bool:
parts = p.split("/")
return bool(p) and ".." not in parts and not p.startswith("/") Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.
Related errors
- Category file path ' ' is outside the allowed categories…
- cannot be a dot path segment
- git-subdir 'path' must be a relative path of the form…
- Invalid file path : contains URL special characters
- Invalid identifier : path traversal detected
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b928d1981b6cee88.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/bitbucket/bitbucket_client.py:19
"""
BitBucket API client for fetching .prompt files from BitBucket repositories.
"""
import base64
import urllib.parse
from typing import Any, Final
from litellm.llms.custom_httpx.http_handler import HTTPHandler
def _sanitize_file_path(file_path: str) -> str:
"""Reject path traversal and URL-encode each path segment."""
if "#" in file_path or "?" in file_path:
raise ValueError(f"Invalid file path {file_path!r}: contains URL special characters")
parts: Final = file_path.split("/")
for part in parts:
if part == "..":
raise ValueError(f"Invalid file path {file_path!r}: path traversal detected")
return "/".join(urllib.parse.quote(part, safe="") for part in parts)
class BitBucketClient:
"""
Client for interacting with BitBucket API to fetch .prompt files.
Supports:
- Authentication with access tokens
- Fetching file contents from repositories
- Team-based access control through BitBucket permissions
- Branch-specific file fetching
"""
def __init__(self, config: dict[str, Any]):
"""
Initialize the BitBucket client.
View on GitHub (pinned to 77b7c6c40c)