fix(proxy): add safe header sanitization and null key/val guards [skip ci]

This commit is contained in:
Kartik Chilkoti 2026-09-16 17:04:18 +05:30
parent a8979fe054
commit b55c09d6fa

View file

@ -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