Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion litellm/llms/bedrock/batches/transformation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import time
from typing import Any, Dict, List, Literal, Optional, Union, cast

Expand Down Expand Up @@ -294,7 +295,8 @@ def transform_retrieve_batch_request(
raise ValueError(f"Invalid ARN format: {batch_id}")

region = arn_parts[3]
# arn_parts[5] contains "model-invocation-job/{jobId}"
if not re.match(r"^[a-z][a-z0-9-]*$", region):
raise ValueError(f"Invalid region in ARN: {batch_id}")

# Build the endpoint URL for GetModelInvocationJob
# AWS API format: GET /model-invocation-job/{jobIdentifier}
Expand Down
3 changes: 3 additions & 0 deletions litellm/llms/s3_vectors/vector_stores/transformation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

import httpx
Expand Down Expand Up @@ -66,6 +67,8 @@ def get_complete_url(self, api_base: Optional[str], litellm_params: dict) -> str
aws_region_name = litellm_params.get("aws_region_name")
if not aws_region_name:
raise ValueError("aws_region_name is required for S3 Vectors")
if not re.match(r"^[a-z][a-z0-9-]*$", aws_region_name):
raise ValueError("Invalid aws_region_name format")
return f"https://s3vectors.{aws_region_name}.api.aws"

def transform_search_vector_store_request(
Expand Down
3 changes: 3 additions & 0 deletions litellm/llms/snowflake/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import TYPE_CHECKING, Any, List, Optional, Tuple

from litellm.secret_managers.main import get_secret_str
Expand Down Expand Up @@ -61,6 +62,8 @@ def _get_api_base(self, api_base, optional_params):
account_id = get_secret_str("SNOWFLAKE_ACCOUNT_ID")
if account_id is None:
raise ValueError("Missing snowflake account_id")
if not re.match(r"^[a-zA-Z0-9_-]+$", account_id):
raise ValueError("Invalid account_id format")
Comment on lines +65 to +66

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Regex rejects valid Snowflake account identifiers containing dots

Snowflake supports a legacy account identifier format <account_locator>.<region_id>.<cloud> (e.g., xy12345.us-east-1.aws) that is interpolated directly into the URL as https://{account_id}.snowflakecomputing.com/api/v2. The regex ^[a-zA-Z0-9_-]+$ forbids dots, so any existing caller using the locator+region format will start getting ValueError after this change — a silent backwards-incompatible breakage (see rule on avoiding breaking changes without feature flags). The regex needs to permit dots, or the validation should be scoped to the new-format account names only.

Rule Used: What: avoid backwards-incompatible changes without... (source)

api_base = f"https://{account_id}.snowflakecomputing.com/api/v2"

api_base = api_base.rstrip("/")
Expand Down
7 changes: 5 additions & 2 deletions litellm/llms/vertex_ai/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ def get_vertex_base_url(
"""
if vertex_location == "global":
return "https://aiplatform.googleapis.com"
else:
return f"https://{vertex_location}-aiplatform.googleapis.com"
if vertex_location is not None and not re.match(
r"^[a-z][a-z0-9-]*$", vertex_location
):
raise ValueError("Invalid vertex_location format")
return f"https://{vertex_location}-aiplatform.googleapis.com"
Comment on lines +235 to +239

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 None location silently produces an invalid URL

When vertex_location is None, the is not None guard skips the regex check and the function returns "https://None-aiplatform.googleapis.com" — a syntactically valid URL that will simply 404 or resolve to an unintended host. The same issue exists in the pass-through copy (llm_passthrough_endpoints.py). While this bug pre-dates the PR, the guard clause makes it explicit and adds a clear hook to fix it. Consider raising ValueError when vertex_location is None instead of silently passing through.



def _get_embedding_url(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import json
import os
import re
from typing import Any, Optional, Tuple, Union, cast

import httpx
Expand Down Expand Up @@ -1500,6 +1501,10 @@ def get_vertex_base_url(vertex_location: Optional[str]) -> str:
"""
if vertex_location == "global":
return "https://aiplatform.googleapis.com/"
if vertex_location is not None and not re.match(
r"^[a-z][a-z0-9-]*$", vertex_location
):
raise ValueError("Invalid vertex_location format")
return f"https://{vertex_location}-aiplatform.googleapis.com/"


Expand Down
Loading