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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into fix/strip-pricing-fields-pr27071
user6a3f6b47de5e
diff --cc litellm/proxy/litellm_pre_call_utils.pyindex 7e0054b33f0,3b22397559f..7cf36fc9d5c--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@@ -155,20 -168,45 +169,59 @@@ _ALLOW_CLIENT_MESSAGE_REDACTION_OPT_OUT"allow_client_message_redaction_opt_out")+# Per-request pricing parameters mutate cost-tracking output and (via+# ``litellm.completion`` → ``register_model``) the process-wide+# ``litellm.model_cost`` map. Both effects belong to deployment configuration,+# not to user-supplied request bodies, so the proxy strips them before they+# reach the call path. Built from the Pydantic model so newly-added pricing+# fields are covered automatically.+_CLIENT_PRICING_CONTROL_FIELDS = frozenset(+ CustomPricingLiteLLMParams.model_fields.keys()+)+# ``model_info`` carries the same pricing fields when read by+# ``use_custom_pricing_for_model``; strip from metadata for the same reason.+_CLIENT_PRICING_METADATA_FIELDS = frozenset({"model_info"})+_ALLOW_CLIENT_PRICING_OVERRIDE_METADATA_KEY = "allow_client_pricing_override"++ # Request fields whose value, when URL-valued, becomes the outbound destination+ # for a provider call. Letting a proxy caller pin the destination is an SSRF+ # primitive (HuggingFace/Oobabooga `model`, Gemini files `file_id`); guard+ # them centrally so SDK users keep working but proxy users default-deny.+ _URL_DESTINATION_REQUEST_FIELDS = ("model", "file_id")+++ def _reject_url_valued_destinations(data: Dict[str, Any]) -> None:+ """Reject URL-valued ``model``/``file_id`` unless admin-allowlisted.++ Some providers (HuggingFace, Oobabooga, Gemini files) accept a URL in the+ identifier field and use it as the outbound destination. On the proxy that+ is an SSRF primitive — a low-privilege caller can point traffic at any+ host the proxy can reach, including internal services. Reject here at the+ proxy boundary so SDK users (who legitimately pass URL-valued identifiers)+ are unaffected, while admins can opt specific hosts back in via+ ``litellm.provider_url_destination_allowed_hosts``.+ """+ allowed_hosts = getattr(litellm, "provider_url_destination_allowed_hosts", []) or []+ for field in _URL_DESTINATION_REQUEST_FIELDS:+ value = data.get(field)+ if not isinstance(value, str) or not value.startswith(("http://", "https://")):+ continue+ if is_url_destination_allowed_by_host(value, allowed_hosts):+ continue+ raise HTTPException(+ status_code=400,+ detail={+ "error": "invalid_request",+ "param": field,+ "message": (+ f"URL-valued '{field}' is not allowed. Configure custom "+ "endpoints with api_base instead, or add the destination "+ "host to `provider_url_destination_allowed_hosts` in "+ "litellm_settings."+ ),+ },+ )+def _strip_untrusted_request_header_controls(headers: Any,