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]

chore(proxy): coerce stringified nested-config containers before descent

user5e56022553df
diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py
index 5d7a37afd4c..8012a9be768 100644
--- a/litellm/proxy/auth/auth_utils.py
+++ b/litellm/proxy/auth/auth_utils.py
@@ -352,8 +352,8 @@ def is_request_body_safe(
"""
_check_banned_params(request_body, general_settings, llm_router, model)
for nested_key in _NESTED_CONFIG_KEYS:
- nested = request_body.get(nested_key)
- if isinstance(nested, dict):
+ nested = _coerce_metadata_to_dict(request_body.get(nested_key))
+ if nested is not None:
_check_banned_params(nested, general_settings, llm_router, model)
for metadata_key in _NESTED_METADATA_KEYS:
metadata = _coerce_metadata_to_dict(request_body.get(metadata_key))
diff --git a/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py b/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py
index 37f9e8c9528..fd33f22480b 100644
--- a/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py
+++ b/tests/test_litellm/proxy/auth/test_banned_params_extra_body.py
@@ -80,3 +80,25 @@ def test_admin_opt_in_still_permits_extra_body_credentials():
llm_router=None,
model="openai/gpt-4",
)
+
+
+def test_banned_param_under_stringified_extra_body_is_rejected():
+ # Raw-HTTP and multipart/form-data clients can send ``extra_body`` as
+ # a JSON-encoded string rather than an object. An ``isinstance(...,
+ # dict)`` guard on the nested descent would skip such payloads,
+ # leaving the banned-key check bypassed. Coercion via
+ # ``_coerce_metadata_to_dict`` closes that variant.
+ import json
+
+ body = {
+ "model": "bedrock/anthropic.claude-v2",
+ "messages": [{"role": "user", "content": "x"}],
+ "extra_body": json.dumps({"aws_web_identity_token": "anything"}),
+ }
+ with pytest.raises(ValueError, match="not allowed in request body"):
+ is_request_body_safe(
+ request_body=body,
+ general_settings={},
+ llm_router=None,
+ model="bedrock/anthropic.claude-v2",
+ )