Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(gemini): validate fully decoded file names

user19f8c1013b69
diff --git a/litellm/llms/gemini/files/transformation.py b/litellm/llms/gemini/files/transformation.py
index fe7f81ab95d..d282878a4a5 100644
--- a/litellm/llms/gemini/files/transformation.py
+++ b/litellm/llms/gemini/files/transformation.py
@@ -279,7 +279,7 @@ class GoogleAIStudioFilesHandler(GeminiModelInfo, BaseFilesConfig):
decoded_file_id = ""
if len(parts) == 2:
decoded_file_id = parts[1]
- for _ in range(3):
+ while True:
next_decoded_file_id = unquote(decoded_file_id)
if next_decoded_file_id == decoded_file_id:
break
diff --git a/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py b/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
index 93188da9c91..334c691fdba 100644
--- a/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
+++ b/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
@@ -133,6 +133,16 @@ class TestGoogleAIStudioFilesTransformation:
litellm_params=litellm_params,
)
+ def test_transform_retrieve_file_request_rejects_deeply_encoded_separator(self):
+ litellm_params = {"api_key": "test-api-key"}
+
+ with pytest.raises(ValueError, match="Invalid Gemini file name"):
+ self.handler.transform_retrieve_file_request(
+ file_id="files/..%2525252Fsecrets",
+ optional_params={},
+ litellm_params=litellm_params,
+ )
+
@patch.dict("os.environ", {}, clear=True)
@patch("litellm.llms.gemini.common_utils.get_secret_str", return_value=None)
def test_transform_retrieve_file_request_missing_api_key(self, mock_get_secret):