From b55c09d6fa13d34ca1ff5a02e6a0f559150be2b5 Mon Sep 17 00:00:00 2001 From: Kartik Chilkoti Date: Wed, 16 Sep 2026 17:04:18 +0530 Subject: [PATCH] fix(proxy): add safe header sanitization and null key/val guards [skip ci] --- litellm/proxy/utils/header_sanitizer.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 litellm/proxy/utils/header_sanitizer.py 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