fix: restrict x-pass- header forwarding for protected header names

This commit is contained in:
Yuneng Jiang 2026-04-16 15:35:43 -07:00
parent 7279dca929
commit f46e9959db
No known key found for this signature in database

View file

@ -56,11 +56,15 @@ class BasePassthroughUtils:
# Combine request headers with custom headers
headers = {**request_headers, **headers}
# Always process x-pass- prefixed headers (strip prefix and forward)
# Process x-pass- prefixed headers (strip prefix and forward)
# Certain protocol-level and credential headers are excluded from this mechanism.
_PROTECTED_HEADERS = {"authorization", "api-key", "host", "content-length"}
for header_name, header_value in request_headers.items():
if header_name.lower().startswith(PASS_THROUGH_HEADER_PREFIX):
# Strip the 'x-pass-' prefix to get the actual header name
actual_header_name = header_name[len(PASS_THROUGH_HEADER_PREFIX) :]
if actual_header_name.lower() in _PROTECTED_HEADERS:
continue
headers[actual_header_name] = header_value
return headers