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): scrub remote-URL module loads from DB-overlay config

user7575df2549a6
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 9c9c00d59c8..f7cb767d891 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -3105,6 +3105,107 @@ class StreamingCallbackError(Exception):
pass
+# Fields in ``litellm_settings`` / ``general_settings`` whose values flow
+# into ``get_instance_fn`` during config load. Remote-URL values
+# (``s3://`` / ``gcs://``) are scrubbed from these when the value
+# originates from a DB-overlay merge: at the point ``get_instance_fn``
+# is invoked, ``config_file_path`` is non-None (the YAML load chain is
+# active), so the runtime gate cannot distinguish a YAML-sourced value
+# from a DB-sourced value. Scrubbing at the merge boundary closes that
+# gap without tracking source on every config dict entry.
+_DB_OVERLAY_REMOTE_MODULE_STR_FIELDS: Dict[str, Tuple[str, ...]] = {
+ "litellm_settings": ("post_call_rules",),
+ "general_settings": (
+ "custom_auth",
+ "custom_key_generate",
+ "custom_key_update",
+ "custom_sso",
+ "custom_ui_sso_sign_in_handler",
+ ),
+}
+_DB_OVERLAY_REMOTE_MODULE_LIST_FIELDS: Dict[str, Tuple[str, ...]] = {
+ "litellm_settings": (
+ "callbacks",
+ "success_callback",
+ "failure_callback",
+ "audit_log_callbacks",
+ ),
+}
+
+
+def _is_remote_module_url(value: Any) -> bool:
+ return isinstance(value, str) and (
+ value.startswith("s3://") or value.startswith("gcs://")
+ )
+
+
+def _scrub_db_overlay_remote_module_loads(section: str, db_value: Any) -> Any:
+ """Strip ``s3://`` / ``gcs://`` entries from the DB-overlay value for
+ fields whose contents reach ``get_instance_fn``. The same scheme is
+ allowed from a YAML config (the documented operator flow) but a
+ DB-overlay write would otherwise smuggle the same payload through
+ the YAML-load chain and reach ``_load_instance_from_remote_storage``."""
+ if not isinstance(db_value, dict):
+ return db_value
+ str_fields = _DB_OVERLAY_REMOTE_MODULE_STR_FIELDS.get(section, ())
+ list_fields = _DB_OVERLAY_REMOTE_MODULE_LIST_FIELDS.get(section, ())
+ if not str_fields and not list_fields and section != "general_settings":
+ return db_value
+ sanitized = copy.deepcopy(db_value)
+ for field in str_fields:
+ v = sanitized.get(field)
+ if _is_remote_module_url(v):
+ verbose_proxy_logger.warning(
+ "Refused remote-URL value for DB-overlay %s.%s=%r; only "
+ "config.yaml entries may reference s3:// / gcs:// modules.",
+ section,
+ field,
+ v,
+ )
+ sanitized[field] = None
+ for field in list_fields:
+ v = sanitized.get(field)
+ if isinstance(v, list):
+ cleaned = [item for item in v if not _is_remote_module_url(item)]
+ if len(cleaned) != len(v):
+ verbose_proxy_logger.warning(
+ "Refused %d remote-URL entries from DB-overlay %s.%s; "
+ "only config.yaml entries may reference s3:// / gcs:// "
+ "modules.",
+ len(v) - len(cleaned),
+ section,
+ field,
+ )
+ sanitized[field] = cleaned
+ # ``custom_provider_map`` is a list of dicts with ``custom_handler`` —
+ # walk it explicitly.
+ if section == "litellm_settings":
+ cpm = sanitized.get("custom_provider_map")
+ if isinstance(cpm, list):
+ for item in cpm:
+ if isinstance(item, dict) and _is_remote_module_url(
+ item.get("custom_handler")
+ ):
+ verbose_proxy_logger.warning(
+ "Refused remote-URL custom_handler from DB-overlay "
+ "litellm_settings.custom_provider_map: %r",
+ item.get("custom_handler"),
+ )
+ item["custom_handler"] = None
+ # ``general_settings.litellm_jwtauth.custom_validate`` is a nested
+ # string field.
+ if section == "general_settings":
+ jwt = sanitized.get("litellm_jwtauth")
+ if isinstance(jwt, dict) and _is_remote_module_url(jwt.get("custom_validate")):
+ verbose_proxy_logger.warning(
+ "Refused remote-URL custom_validate from DB-overlay "
+ "general_settings.litellm_jwtauth: %r",
+ jwt.get("custom_validate"),
+ )
+ jwt["custom_validate"] = None
+ return sanitized
+
+
class ProxyConfig:
"""
Abstraction class on top of config loading/updating logic. Gives us one place to control all config updating logic.
@@ -5282,6 +5383,15 @@ class ProxyConfig:
else:
d[k] = v
+ # Strip remote-URL module loads from the DB-overlay before merge —
+ # the YAML-load callsites have ``config_file_path`` set, so a
+ # DB-sourced ``s3://`` value would otherwise reach
+ # ``_load_instance_from_remote_storage`` without going through
+ # the runtime gate.
+ db_param_value = _scrub_db_overlay_remote_module_loads(
+ section=param_name, db_value=db_param_value
+ )
+
if param_name == "environment_variables":
decrypted_env_vars = self._decrypt_and_set_db_env_variables(
db_param_value, return_original_value=True
diff --git a/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py b/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py
new file mode 100644
index 00000000000..01ece825f0e
--- /dev/null
+++ b/tests/test_litellm/proxy/types_utils/test_db_overlay_remote_module_scrub.py
@@ -0,0 +1,122 @@
+"""
+Regression tests: ``s3://`` / ``gcs://`` values in DB-overlay config
+must be stripped at the merge boundary so they never reach
+``get_instance_fn`` with ``config_file_path`` set.
+
+Without this scrub, a PROXY_ADMIN who persists e.g.
+``litellm_settings.success_callback: ["s3://attacker/m.i"]`` via
+``/config/update`` would have it merged into the in-memory config
+during the next ``load_config`` cycle. The YAML-load chain is active
+at that point, so the runtime gate in ``get_instance_fn`` (which
+permits remote loads when ``config_file_path`` is non-None) would
+pass and ``_load_instance_from_remote_storage`` would exec the
+remote module.
+"""
+
+import os
+import sys
+
+import pytest
+
+sys.path.insert(
+ 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../.."))
+)
+
+from litellm.proxy.proxy_server import ( # noqa: E402
+ _scrub_db_overlay_remote_module_loads,
+)
+
+
+ "field",
+ ["callbacks", "success_callback", "failure_callback", "audit_log_callbacks"],
+)
+def test_litellm_settings_callback_list_strips_remote_urls(field):
+ overlay = {field: ["langfuse", "s3://attacker/m.i", "gcs://attacker/m.i"]}
+ cleaned = _scrub_db_overlay_remote_module_loads("litellm_settings", overlay)
+ assert cleaned[field] == ["langfuse"]
+
+
+ "field",
+ [
+ "custom_auth",
+ "custom_key_generate",
+ "custom_key_update",
+ "custom_sso",
+ "custom_ui_sso_sign_in_handler",
+ ],
+)
+def test_general_settings_str_field_strips_remote_urls(field):
+ overlay = {field: "s3://attacker/m.i"}
+ cleaned = _scrub_db_overlay_remote_module_loads("general_settings", overlay)
+ assert cleaned[field] is None
+
+
+def test_litellm_settings_post_call_rules_str_stripped():
+ overlay = {"post_call_rules": "gcs://attacker/m.i"}
+ cleaned = _scrub_db_overlay_remote_module_loads("litellm_settings", overlay)
+ assert cleaned["post_call_rules"] is None
+
+
+def test_custom_provider_map_custom_handler_stripped():
+ overlay = {
+ "custom_provider_map": [
+ {"provider": "ok", "custom_handler": "my_module.handler"},
+ {"provider": "bad", "custom_handler": "s3://attacker/m.i"},
+ ]
+ }
+ cleaned = _scrub_db_overlay_remote_module_loads("litellm_settings", overlay)
+ assert cleaned["custom_provider_map"][0]["custom_handler"] == "my_module.handler"
+ assert cleaned["custom_provider_map"][1]["custom_handler"] is None
+
+
+def test_litellm_jwtauth_custom_validate_stripped():
+ overlay = {
+ "litellm_jwtauth": {
+ "user_id_jwt_field": "sub",
+ "custom_validate": "s3://attacker/m.validator",
+ }
+ }
+ cleaned = _scrub_db_overlay_remote_module_loads("general_settings", overlay)
+ assert cleaned["litellm_jwtauth"]["custom_validate"] is None
+ # Sibling fields preserved.
+ assert cleaned["litellm_jwtauth"]["user_id_jwt_field"] == "sub"
+
+
+def test_local_dotted_name_preserved():
+ # The scrub only targets s3:// / gcs:// scheme prefixes — legitimate
+ # dotted module names (the documented operator flow) must pass
+ # through unchanged.
+ overlay = {
+ "success_callback": ["langfuse", "my_module.success_handler", "datadog"],
+ "post_call_rules": "my_module.rule_fn",
+ }
+ cleaned = _scrub_db_overlay_remote_module_loads("litellm_settings", overlay)
+ assert cleaned["success_callback"] == [
+ "langfuse",
+ "my_module.success_handler",
+ "datadog",
+ ]
+ assert cleaned["post_call_rules"] == "my_module.rule_fn"
+
+
+def test_non_dict_overlay_passthrough():
+ # Some DB-overlay values are scalars (e.g. ``max_internal_user_budget:
+ # 100.0``). The scrub must not break those.
+ assert _scrub_db_overlay_remote_module_loads("litellm_settings", 100.0) == 100.0
+ assert _scrub_db_overlay_remote_module_loads("litellm_settings", None) is None
+
+
+def test_unknown_section_passthrough():
+ overlay = {"success_callback": ["s3://anything"]}
+ # ``router_settings`` isn't a section with module-loading fields —
+ # the scrub leaves it alone.
+ cleaned = _scrub_db_overlay_remote_module_loads("router_settings", overlay)
+ assert cleaned == overlay
+
+
+def test_scrub_does_not_mutate_input():
+ original = {"success_callback": ["s3://attacker/m.i"]}
+ _scrub_db_overlay_remote_module_loads("litellm_settings", original)
+ assert original["success_callback"] == ["s3://attacker/m.i"]