diff --git a/litellm/proxy/utils/header_sanitizer.py b/litellm/proxy/utils/header_sanitizer.py new file mode 100644 index 00000000000..eac87d68d1b --- /dev/null +++ b/litellm/proxy/utils/header_sanitizer.py @@ -0,0 +1,20 @@ +\"\"\" +Header sanitization and guard utilities for LiteLLM proxy authentication forwarding. +\"\"\" +from typing import Dict, Any, Optional + +def sanitize_proxy_headers(headers: Optional[Dict[str, Any]]) -> Dict[str, str]: + if not headers: + return {} + + sanitized: Dict[str, str] = {} + for k, v in headers.items(): + if k is None: + continue + key_str = str(k).strip() + if not key_str: + continue + val_str = "" if v is None else str(v).strip() + sanitized[key_str] = val_str + + return sanitized \ No newline at end of file