Repository navigation
[Fix] Restrict x-pass- header forwarding for credential and protocol headers #25916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"} | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a user was intentionally forwarding an 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,
)
continueRule Used: What: avoid backwards-incompatible changes without... (source)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Defining
Suggested change
|
||||||||||||||||
| 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) :] | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| if actual_header_name.lower() in _PROTECTED_HEADERS: | ||||||||||||||||
| continue | ||||||||||||||||
| headers[actual_header_name] = header_value | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No test in the committed test suite exercises the Per the project's testing guidelines, a test (or several) should be added to
|
||||||||||||||||
|
|
||||||||||||||||
| return headers | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
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-keyto overwrite the Anthropicx-api-keyheader set byvalidate_environment, orx-pass-x-goog-api-key: keyfor Google AI Studio. Sinceforward_headers_from_requestprocessesx-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:
A prefix-based block on
x-amz-would also prevent AWS SigV4 header tampering for Bedrock passthrough, thoughsign_requestmay re-sign after this point.