Repository navigation
(Security) - Prevent potential Anthropic key exposure through advisor tool client-side credential overrides - #32093
Conversation
Greptile SummaryThis PR hardens the credential-resolution path for advisor sub-calls by introducing
Confidence Score: 5/5Safe to merge — the new credential resolver correctly enforces all preconditions before any external URL is used, and the existing integration tests have been updated to avoid live DNS queries. The change is tightly scoped to _resolve_advisor_credentials() and its call site. The HTTPS + ssl_verify=True preconditions are checked before validate_url() is invoked, so the discarded return value is consistently safe. Every new branch has a corresponding unit test, and the integration helper correctly patches validate_url to keep the test suite offline. No regressions are expected in the default-off path. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py | Adds _resolve_advisor_credentials() to enforce api_key requirement alongside api_base, HTTPS-only scheme, ssl_verify=True, and SSRF validation via validate_url(); validate_url return value is intentionally discarded because HTTPS + ssl_verify=True preconditions guarantee it returns the URL unchanged. |
| tests/test_litellm/llms/anthropic/messages/test_advisor_orchestration.py | Adds nine focused unit tests for _resolve_advisor_credentials() covering gate-closed, key-without-base, base-without-key, SSRF propagation, validation skip, cloud-metadata block, non-HTTPS rejection, ssl_verify=False rejection, and real public IP allowance; integration helper correctly patches validate_url to avoid live DNS lookups. |
Reviews (3): Last reviewed commit: "fix(anthropic): also reject advisor api_..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…advisor tool The advisor_20260301 interceptor honored a caller-supplied api_base once allow_client_side_credentials was enabled, even without a caller-supplied api_key. AnthropicModelInfo.get_auth_header() then fell back to the proxy's own ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN, so the server's real credentials plus the conversation history got sent to a caller-chosen destination _resolve_advisor_credentials() now only honors api_base alongside a non-empty caller-supplied api_key, requires the https scheme, and validates api_base via validate_url() before use, mirroring check_complete_credentials in auth_utils.py. https is required because validate_url only DNS-pins the connection for http; for https with TLS verification on it returns the URL unchanged and relies on certificate validation to block DNS rebinding
5cf2702 to
388b6ec
Compare
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
validate_url only DNS-pins the connection for http, or for https with litellm.ssl_verify disabled; the previous https-only check missed the ssl_verify=False case, where validate_url's rewritten URL was still being discarded, per Greptile's review of this PR. Reject api_base outright when ssl_verify is False so the discarded rewrite can no longer matter
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9c77815. Configure here.
| return general_settings.get("allow_client_side_credentials") is True | ||
|
|
||
|
|
||
| def _resolve_advisor_credentials(advisor_tool: dict) -> tuple[Optional[str], Optional[str]]: |
There was a problem hiding this comment.
🟡 New helper uses an untyped dictionary parameter against repo typing rules
The advisor-credential resolver declares its input as a bare dictionary (advisor_tool: dict at litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py:182) in newly added code, so the parameter is not strongly typed.
Impact: Violates the repository's mandatory typing convention for new code.
Rule source in CLAUDE.md
CLAUDE.md states for new/updated code: "Fully typed; no Any or coarse types like dict[str, Any] or just dict. Every function parameter must be strongly typed". _resolve_advisor_credentials is a newly added function whose only parameter is annotated with the coarse dict type.
Was this helpful? React with 👍 or 👎 to provide feedback.
…advisor tool (#32093) * fix(anthropic): require caller api_key and SSRF-validate api_base in advisor tool The advisor_20260301 interceptor honored a caller-supplied api_base once allow_client_side_credentials was enabled, even without a caller-supplied api_key. AnthropicModelInfo.get_auth_header() then fell back to the proxy's own ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN, so the server's real credentials plus the conversation history got sent to a caller-chosen destination _resolve_advisor_credentials() now only honors api_base alongside a non-empty caller-supplied api_key, requires the https scheme, and validates api_base via validate_url() before use, mirroring check_complete_credentials in auth_utils.py. https is required because validate_url only DNS-pins the connection for http; for https with TLS verification on it returns the URL unchanged and relies on certificate validation to block DNS rebinding * fix(anthropic): also reject advisor api_base when ssl_verify is disabled validate_url only DNS-pins the connection for http, or for https with litellm.ssl_verify disabled; the previous https-only check missed the ssl_verify=False case, where validate_url's rewritten URL was still being discarded, per Greptile's review of this PR. Reject api_base outright when ssl_verify is False so the discarded rewrite can no longer matter (cherry picked from commit 07b9ea8)
Security impact
This closes a critical credential-leak and SSRF path in advisor orchestration, reachable when
allow_client_side_credentialsis enabled. The advisor tool extracted a caller-suppliedapi_basewithout requiring a callerapi_keyand without SSRF-validating the destination. Because the Anthropic auth path falls back to the proxy's own credentials when no key is supplied, a caller could point the advisor sub-call at an attacker-controlled or internal URL and have the server's real Anthropic key, plus the full conversation content, sent there, while the caller-facing response looked normal. The fix honors a callerapi_baseonly alongside a non-empty callerapi_key, requireshttpswith TLS verification, and validates the destination against the SSRF guard.Severity: Critical, gated behind an opt-in. Only exploitable when
allow_client_side_credentialsis on; where on, it silently exfiltrates the server's Anthropic key and conversation dataRelevant issues
Linear ticket
Resolves LIT-4198
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Verified against a live proxy with
general_settings.allow_client_side_credentials: true, using a local listener standing in for an attacker-controlled endpoint. Before the fix, an advisor tool definition that set a customapi_basewithout also supplying anapi_keycaused the proxy's own Anthropic credentials, plus the conversation content, to be sent to that endpoint, while the caller-facing response looked completely normal.After the fix, the same request is rejected before any outbound call is made, with no data reaching the listener. Also verified live: an internal/cloud-metadata-style destination is blocked by the SSRF guard even when the caller supplies their own credential, a non-
httpsdestination is rejected outright regardless of credentials, and the legitimate flow (caller's own credential paired with an admin-allowlisted destination) continues to work unchanged, with the caller's own credential (not the server's) reaching the destination.Full request/response detail from this verification is available on request rather than published here, since it doubles as a working reproduction of the underlying issue.
The https-scheme requirement is additionally covered by an unmocked unit test that performs real DNS resolution against a real public address and confirms it is honored.
Type
🐛 Bug Fix
Changes
AdvisorOrchestrationHandler(litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py) extracted a caller-suppliedapi_base/api_keyfrom the advisor tool definition oncegeneral_settings.allow_client_side_credentialswas enabled, without requiring the caller to also supply their ownapi_keyand without validatingapi_baseagainst SSRF. BecauseAnthropicModelInfo.get_auth_header()falls back to the proxy's own Anthropic credentials when no key is given, a caller who could set a client-sideapi_basecould redirect the advisor sub-call, and the server's real credentials plus the conversation history, to an attacker-controlled or internal address._resolve_advisor_credentials()now only honors a caller-suppliedapi_basealongside a non-empty caller-suppliedapi_key, requires thehttpsscheme withlitellm.ssl_verifyon, and validatesapi_baseviavalidate_url()before use (respecting the existinglitellm.user_url_validationtoggle), mirroring the intent already documented oncheck_complete_credentialsinproxy/auth/auth_utils.py. Thehttps/ssl_verifyrequirement matters becausevalidate_urlonly rewrites the connection to a DNS-pinned address forhttp, or forhttpswith TLS verification disabled; otherwise it returns the URL unchanged and relies on certificate validation to block DNS rebinding, so this closes that gap without threading a pinned address and Host-header override through the wholeanthropic_messages()call chain.check_complete_credentialsitself has the same discarded-rewrite pattern for its own SSRF check, but it currently has zero call sites in the codebase; filed as LIT-4203 so it isn't silently re-wired in without also closing that gap. This PR only changes behavior whenallow_client_side_credentialsis enabled; the default-closed gate is unchangedNote
High Risk
Security fix in proxy advisor routing when clientside credentials are enabled; incorrect validation could block legitimate routing or leave SSRF/credential exfil paths open.
Overview
Closes a credential-leak and SSRF path when
allow_client_side_credentialsis on and the advisor tool supplies a customapi_base.Advisor orchestration now resolves client routing through
_resolve_advisor_credentials()instead of copyingapi_key/api_basefrom the tool inline. A callerapi_baseis accepted only with a non-empty callerapi_key, so the proxy’s Anthropic credentials are not sent to an attacker-chosen URL.api_basemust behttps://,litellm.ssl_verifymust be enabled, andvalidate_url()runs whenuser_url_validationis on (same SSRF posture as proxy credential checks). The existing clientside-credentials gate is unchanged when the opt-in is off.Tests cover the new helper (pairing rules, HTTPS/TLS gates, SSRF including cloud metadata, and honoring public HTTPS IPs) and patch
validate_urlin integration-style advisor sub-call tests.Reviewed by Cursor Bugbot for commit 9c77815. Bugbot is set up for automated code reviews on this repo. Configure here.