Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion litellm/passthrough/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ def forward_headers_from_request(
# 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"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: Incomplete credential header blocklist

The protected set misses provider-specific credential headers. An authenticated user can send x-pass-x-api-key: attacker-key to overwrite the Anthropic x-api-key header set by validate_environment, or x-pass-x-goog-api-key: key for Google AI Studio. Since forward_headers_from_request processes x-pass- headers after auth headers are set (overwriting them at line 68), this lets a user substitute the operator's downstream API key with their own, bypassing spend tracking and billing controls.

Consider either switching to an allowlist approach, or at minimum adding the known provider credential headers:

Suggested change
_PROTECTED_HEADERS = {"authorization", "api-key", "host", "content-length"}
_PROTECTED_HEADERS = {"authorization", "api-key", "host", "content-length", "x-api-key", "x-goog-api-key"}

A prefix-based block on x-amz- would also prevent AWS SigV4 header tampering for Bedrock passthrough, though sign_request may re-sign after this point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent drop may break legitimate use cases

If a user was intentionally forwarding an authorization header to a downstream service that expects a different credential than LiteLLM's own auth (e.g., x-pass-authorization: Bearer <downstream-token>), this change silently drops it without any log message, warning, or config flag to opt out. Per the project's backwards-compatibility rule, a behaviour change that drops previously-accepted input should ideally be guarded by a feature flag or at minimum log a warning so the caller knows the header was skipped.

if actual_header_name.lower() in _PROTECTED_HEADERS:
    verbose_proxy_logger.warning(
        "Skipping x-pass- header %s: maps to a protected header name",
        header_name,
    )
    continue

Rule Used: What: avoid backwards-incompatible changes without... (source)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 _PROTECTED_HEADERS should be a module-level constant

Defining _PROTECTED_HEADERS as a local variable inside forward_headers_from_request re-creates the set on every call and makes the list invisible to callers who might want to inspect or extend it. Moving it to module level matches common Python conventions and eliminates the per-call allocation.

Suggested change
_PROTECTED_HEADERS = {"authorization", "api-key", "host", "content-length"}
_PROTECTED_HEADERS: frozenset = frozenset(
{"authorization", "api-key", "host", "content-length"}
)
class BasePassthroughUtils:

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) :]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Stripped header name preserves original casing when written

actual_header_name retains the casing of the incoming request header (e.g. x-pass-Anthropic-Beta → Anthropic-Beta), because only the .lower() comparison against _PROTECTED_HEADERS is normalized — the value written into headers on line 68 still uses actual_header_name as-is. Two callers sending x-pass-Custom-Header and x-pass-custom-header would produce distinct keys in the output dict. If the intent is case-insensitive uniqueness in the output, normalise the key on write as well:

Suggested change
actual_header_name = header_name[len(PASS_THROUGH_HEADER_PREFIX) :]
actual_header_name = header_name[len(PASS_THROUGH_HEADER_PREFIX):].lower()

if actual_header_name.lower() in _PROTECTED_HEADERS:
continue
headers[actual_header_name] = header_value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing tests for the new protected-header guard

No test in the committed test suite exercises the _PROTECTED_HEADERS skip path. The PR description states testing was done with standalone scripts in ~/.secfix-scratch/xpass-header/ that were not committed. This means regressions in this security fix are invisible to CI.

Per the project's testing guidelines, a test (or several) should be added to tests/test_litellm/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py covering:

  • x-pass-authorization is silently dropped (not written into headers)
  • x-pass-api-key is silently dropped
  • x-pass-host and x-pass-content-length are silently dropped
  • A non-protected x-pass-* header still works as before


return headers
Expand Down
Loading