Skip to content

(Security) - Prevent potential Anthropic key exposure through advisor tool client-side credential overrides - #32093

Merged
yucheng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_lit_4198_advisor_ssrf
Jul 4, 2026
Merged

yucheng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_lit_4198_advisor_ssrf

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Security impact

This closes a critical credential-leak and SSRF path in advisor orchestration, reachable when allow_client_side_credentials is enabled. The advisor tool extracted a caller-supplied api_base without requiring a caller api_key and 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 caller api_base only alongside a non-empty caller api_key, requires https with TLS verification, and validates the destination against the SSRF guard.

Severity: Critical, gated behind an opt-in. Only exploitable when allow_client_side_credentials is on; where on, it silently exfiltrates the server's Anthropic key and conversation data

Relevant issues

Linear ticket

Resolves LIT-4198

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays 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 custom api_base without also supplying an api_key caused 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-https destination 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-supplied api_base/api_key from the advisor tool definition once general_settings.allow_client_side_credentials was enabled, without requiring the caller to also supply their own api_key and without validating api_base against SSRF. Because AnthropicModelInfo.get_auth_header() falls back to the proxy's own Anthropic credentials when no key is given, a caller who could set a client-side api_base could 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-supplied api_base alongside a non-empty caller-supplied api_key, requires the https scheme with litellm.ssl_verify on, and validates api_base via validate_url() before use (respecting the existing litellm.user_url_validation toggle), mirroring the intent already documented on check_complete_credentials in proxy/auth/auth_utils.py. The https/ssl_verify requirement matters because validate_url only rewrites the connection to a DNS-pinned address for http, or for https with 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 whole anthropic_messages() call chain. check_complete_credentials itself 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 when allow_client_side_credentials is enabled; the default-closed gate is unchanged


Note

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_credentials is on and the advisor tool supplies a custom api_base.

Advisor orchestration now resolves client routing through _resolve_advisor_credentials() instead of copying api_key / api_base from the tool inline. A caller api_base is accepted only with a non-empty caller api_key, so the proxy’s Anthropic credentials are not sent to an attacker-chosen URL. api_base must be https://, litellm.ssl_verify must be enabled, and validate_url() runs when user_url_validation is 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_url in 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.

@greptile-apps

greptile-apps Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens the credential-resolution path for advisor sub-calls by introducing _resolve_advisor_credentials(), which enforces that a caller-supplied api_base is only honored alongside a caller-supplied api_key, requires the HTTPS scheme, rejects litellm.ssl_verify=False, and runs validate_url() for SSRF blocking before use.

  • New credential resolver (_resolve_advisor_credentials): replaces the previous inline extraction with a function that validates all preconditions before returning credentials to the advisor loop.
  • SSRF guard: calls validate_url() to reject private/cloud-metadata addresses; discarding the rewritten URL is safe here because the HTTPS + ssl_verify=True preconditions guarantee validate_url always returns the original URL unchanged.
  • Test coverage: nine new unit tests cover every branch of the new resolver, and the existing integration helper is updated to patch validate_url so hostname resolution doesn't produce live DNS queries.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

greptile-apps[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

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
@yucheng-berri
yucheng-berri force-pushed the litellm_lit_4198_advisor_ssrf branch from 5cf2702 to 388b6ec Compare July 4, 2026 01:13
veria-ai[bot]

This comment was marked as resolved.

@veria-ai

veria-ai Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

greptile-apps[bot]

This comment was marked as resolved.

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
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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.

@yucheng-berri
yucheng-berri merged commit 07b9ea8 into litellm_internal_staging Jul 4, 2026
80 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_lit_4198_advisor_ssrf branch July 4, 2026 19:06

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 1 potential issue.

Open in Devin Review

return general_settings.get("allow_client_side_credentials") is True


def _resolve_advisor_credentials(advisor_tool: dict) -> tuple[Optional[str], Optional[str]]:

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.

🟡 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@yucheng-berri yucheng-berri changed the title fix(anthropic): require caller api_key and SSRF-validate api_base in advisor tool fix(anthropic): patch Anthropic-key exfiltration + SSRF in advisor clientside creds (Critical) Jul 22, 2026
@yucheng-berri yucheng-berri changed the title fix(anthropic): patch Anthropic-key exfiltration + SSRF in advisor clientside creds (Critical) (Security) - Anthropic-key exfiltration + SSRF in advisor clientside creds (Critical) Jul 22, 2026
@yucheng-berri yucheng-berri changed the title (Security) - Anthropic-key exfiltration + SSRF in advisor clientside creds (Critical) (Security) - Prevent potential Anthropic key exposure through advisor tool client-side credential overrides Jul 22, 2026
yuneng-berri pushed a commit that referenced this pull request Aug 8, 2026
…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)
yuneng-berri added a commit that referenced this pull request Aug 8, 2026
…x-0808sec

chore(release): backport #30585, #30867, #31905, #32093, #32405, #34189, #36011 to stable/1.89.x and cut 1.89.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants