fix(proxy): require opt in for audit header fallback

This commit is contained in:
user 2026-04-30 11:17:04 -07:00
parent 09c4d0d01e
commit f48dfdbdd9
2 changed files with 18 additions and 2 deletions

View file

@ -42,7 +42,7 @@ def get_audit_log_changed_by(
) -> Optional[str]:
if litellm_changed_by and _allows_litellm_changed_by_header(user_api_key_dict):
return litellm_changed_by
return user_api_key_dict.user_id or litellm_changed_by or litellm_proxy_admin_name
return user_api_key_dict.user_id or litellm_proxy_admin_name
def _resolve_audit_log_callback(name: str) -> Optional[CustomLogger]:

View file

@ -107,9 +107,25 @@ def test_get_audit_log_changed_by_honors_header_with_team_opt_in():
)
def test_get_audit_log_changed_by_falls_back_to_header_when_user_id_missing():
def test_get_audit_log_changed_by_ignores_header_without_opt_in_when_user_id_missing():
user_api_key_dict = UserAPIKeyAuth(api_key="test-key")
assert (
get_audit_log_changed_by(
litellm_changed_by="spoofed-user",
user_api_key_dict=user_api_key_dict,
litellm_proxy_admin_name="proxy-admin",
)
== "proxy-admin"
)
def test_get_audit_log_changed_by_honors_header_with_opt_in_when_user_id_missing():
user_api_key_dict = UserAPIKeyAuth(
api_key="test-key",
metadata={"allow_litellm_changed_by_header": True},
)
assert (
get_audit_log_changed_by(
litellm_changed_by="delegated-user",