mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): strip CR/LF from echoed caller ids before logging a denied resolution
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
f6821b83f1
commit
ff92afe185
1 changed files with 10 additions and 1 deletions
|
|
@ -30,6 +30,10 @@ def _header(headers: Mapping[str, str], name: str) -> str | None:
|
|||
return value.strip() or None if value is not None else None
|
||||
|
||||
|
||||
def _log_safe(value: str | None) -> str:
|
||||
return (value or "").replace("\r", "").replace("\n", "")
|
||||
|
||||
|
||||
def agent_caller_from_headers(headers: Mapping[str, str], user_api_key_auth: UserAPIKeyAuth) -> AgentCaller | None:
|
||||
"""The caller an agent key is acting for, or ``None`` when the key is not an agent's or no id was echoed."""
|
||||
if not user_api_key_auth.agent_id:
|
||||
|
|
@ -106,6 +110,11 @@ async def agent_caller_resolves(
|
|||
await load_team(user_api_key_auth)
|
||||
await load_user(user_api_key_auth)
|
||||
except Exception as error: # noqa: BLE001 # any failure to resolve the caller must deny, never widen
|
||||
verbose_proxy_logger.warning("agent caller %s could not be resolved, denying: %s", caller, error)
|
||||
verbose_proxy_logger.warning(
|
||||
"agent caller user=%s team=%s could not be resolved (%s), denying",
|
||||
_log_safe(caller.user_id),
|
||||
_log_safe(caller.team_id),
|
||||
type(error).__name__,
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue