Repository navigation
fix(proxy/client): redact api key from key/info client error messages - #31342
Conversation
Greptile SummaryThis PR hardens
Confidence Score: 5/5Safe to merge — all three changed files are scoped to the client-side error path; no auth logic, server behaviour, or database access is touched. The fix is narrow and well-contained: it touches only the error-handling branch of a single client method, relies on an already-tested redact_string helper, and the previous review gaps (unredacted orig_exception storage and missing test assertions) are both resolved in this revision. Regression tests cover str(exc), exc.orig_exception, rendered tracebacks, and the documented residual. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/client/exceptions.py | Adds _redact_orig_exception helper and wires it into both UnauthorizedError and NotFoundError so self.orig_exception stores a redacted copy, closing the gap flagged in the previous review round. |
| litellm/proxy/client/keys.py | Redacts the error message before re-raising on both the 401 and non-401 paths in info(), uses from None to sever the exception chain so the original unredacted error is not reachable via __cause__/__context__, and preserves response for structured access. |
| tests/test_litellm/proxy/client/test_keys.py | Adds four focused regression tests asserting the key is absent from str(exc), orig_exception, and the rendered traceback for both the 404 and 401 paths; also pins the documented residual (exc.response.request.url) with a positive assertion. |
Reviews (5): Last reviewed commit: "fix: preserve key info unauthorized resp..." | Re-trigger Greptile
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
c0e94e3 to
076b454
Compare
|
@greptileai I addressed the orig_exception redaction gap; the exception classes now redact the retained original while preserving its response object. Please re-review |
The keys management client builds GET /key/info?key=<key> and lets the
requests HTTPError propagate. str(HTTPError) renders the failing request URL
verbatim ("... for url: .../key/info?key=sk-..."), so any caller that logs the
exception leaks the full key; the 401 branch leaked the same way through
UnauthorizedError(str(orig_exception))
Redact both branches with the existing redact_secrets helper so the
secret-bearing query param is scrubbed to ?REDACTED while the status code,
reason, and response object are preserved. Server-side responses already mask
the key, so this closes the remaining client-side surface
076b454 to
366eb06
Compare
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: 401 info drops response object
- Updated info() to wrap the original HTTPError for 401 responses so UnauthorizedError keeps a redacted orig_exception with the response attached.
You can send follow-ups to the cloud agent here.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 366eb06. Configure here.
| if e.response.status_code == 401: | ||
| raise UnauthorizedError(e) | ||
| raise | ||
| raise UnauthorizedError(redacted_message) from None |
There was a problem hiding this comment.
401 info drops response object
Medium Severity
For 401 errors in KeysManagementClient.info(), UnauthorizedError is now raised with a redacted string instead of the original HTTPError. This means code expecting to access orig_exception.response will encounter an AttributeError or lose access to the HTTP response details.
Reviewed by Cursor Bugbot for commit 366eb06. Configure here.
|
|
…to v1.90.3 (#257) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [https://github.com/BerriAI/litellm.git](https://github.com/BerriAI/litellm) | patch | `v1.90.0` → `v1.90.3` | --- ### Release Notes <details> <summary>BerriAI/litellm (https://github.com/BerriAI/litellm.git)</summary> ### [`v1.90.3`](https://github.com/BerriAI/litellm/releases/tag/v1.90.3) [Compare Source](BerriAI/litellm@v1.90.2...v1.90.3) #### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.90.3 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.90.3/cosign.pub \ ghcr.io/berriai/litellm:v1.90.3 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** #### What's Changed - chore(release): backport [#​31923](BerriAI/litellm#31923), [#​31929](BerriAI/litellm#31929), [#​31393](BerriAI/litellm#31393) to stable/1.90.x and cut 1.90.3 by [@​mateo-berri](https://github.com/mateo-berri) in [#​32025](BerriAI/litellm#32025) **Full Changelog**: <BerriAI/litellm@v1.90.2...v1.90.3> ### [`v1.90.2`](https://github.com/BerriAI/litellm/releases/tag/v1.90.2) [Compare Source](BerriAI/litellm@v1.90.1...v1.90.2) #### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.90.2 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.90.2/cosign.pub \ ghcr.io/berriai/litellm:v1.90.2 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** #### What's Changed - chore(release): backport [#​31519](BerriAI/litellm#31519), [#​31733](BerriAI/litellm#31733) to stable/1.90.x and cut 1.90.2 by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​31782](BerriAI/litellm#31782) **Full Changelog**: <BerriAI/litellm@v1.90.1...v1.90.2> ### [`v1.90.1`](https://github.com/BerriAI/litellm/releases/tag/v1.90.1) [Compare Source](BerriAI/litellm@v1.90.0-rc.1...v1.90.1) #### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.90.1 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.90.1/cosign.pub \ ghcr.io/berriai/litellm:v1.90.1 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** #### What's Changed - chore(release): backport [#​31036](BerriAI/litellm#31036), [#​31342](BerriAI/litellm#31342), [#​31653](BerriAI/litellm#31653) to stable/1.90.x and cut 1.90.1 (litellm-enterprise 0.1.43.post1) by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​31667](BerriAI/litellm#31667) **Full Changelog**: <BerriAI/litellm@v1.90.0...v1.90.1> </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNDkuNSIsInVwZGF0ZWRJblZlciI6IjQzLjI0OS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=--> Co-authored-by: Renovate Bot <renovate@bhamm-lab.com> Reviewed-on: https://codeberg.org/blake-hamm/bhamm-lab/pulls/257


Relevant issues
Linear ticket
Resolves LIT-4013
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer review (5/5 on the current commit)CI (LiteLLM team)
Branch creation CI run
Link: https://github.com/BerriAI/litellm/pull/31342/checks
CI run for the last commit
Link: https://github.com/BerriAI/litellm/pull/31342/checks
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
KeysManagementClient.info()buildsGET /key/info?key=<key>, so the raw key sits in the request URL. When the proxy returns a non-2xx,requestsraisesHTTPError; its string form and its chained original both carry the URL, so any caller that logs the error or lets it propagate writes the full key to its logsRepro consumer (mirrors how a caller surfaces the error):
Server side is already safe; the 404 body carries no key and the auth error masks it:
BEFORE (unfixed client). The
str(e)log leaks the key, on the 404 path (valid master auth, bad lookup key) and the 401 path (bad key as credential):and
logging.exception()(or an uncaught error) leaks it through the rendered traceback:AFTER (with this fix), both the message and the traceback scrub the query param to
?REDACTED:The happy path is unaffected; a valid lookup still returns the key info:
Edge cases checked against the live proxy:
Redaction stays on even when secret redaction is disabled, because the fix uses the always-on
redact_stringrather than the env-gated wrapper:Type
🐛 Bug Fix
Changes
KeysManagementClient.infoembeds the key in the request URL, and on failure therequestsHTTPErrorstring ("... for url: .../key/info?key=sk-...") flows to whatever logs the exception. The non-401 branch re-raised that error unchanged, and the 401 branch surfaced the same URL throughUnauthorizedError(str(orig_exception)). Beyondstr(e), the original error stayed attached as the chained cause/context, sologging.exception()and an uncaught error printed the key in the rendered traceback tooThis redacts both branches with the always-on
redact_stringhelper fromlitellm_core_utils/secret_redaction. It is deliberately the always-on helper rather than theredact_secretswrapper, since the latter is gated byLITELLM_DISABLE_REDACT_SECRETSand a key-leak fix should not be switchable off by a log-verbosity flag.UnauthorizedErrorandNotFoundErrornow scrub their message;info()raises the wrapped errorsfrom Noneso the unredacted original is not re-attached as the chain, and it hands the already-redacted string toUnauthorizedErrorso the retainedorig_exceptioncarries no secret. The rebuiltHTTPErrorkeeps the originalresponse, so callers and the CLI still readstatus_codeandtextOnly
info()is touched because it is the sole client method that puts the raw key in a URL; the sibling methods (list,generate,delete) build URLs that carry a hashed key and ids rather than the plaintext secret, so they are left as isRedaction is shape and length based (it matches
?key=<value>of 8+ chars andsk-tokens of 20+ chars), which covers real proxy keys and 64-char hashes. The/key/inforoute still accepts the key as a query param, soGET /key/info?key=...can land in proxy access logs and stays reachable via the preserved response object independently of this client fix; moving cross-key lookup to a header or body is a server-side change tracked in LIT-4013Regression tests extend the mapped
tests/test_litellm/proxy/client/test_keys.py; they assert the key is absent fromstr(exc), fromorig_exception, and from the rendered traceback, and they fail on the pre-fix code while passing once the key is scrubbed toREDACTEDOne residual is intentional and pinned by a test: the preserved
responsekeeps the raw key inexc.response.request.url(andexc.request.url), so the rendered string and traceback are scrubbed but the live request URL object is not; removing the key from the URL itself is the server-side root fix tracked in LIT-4013Note
Low Risk
Scoped client-side logging fix with no auth or server behavior changes; preserves
responsefor structured error handling.Overview
Prevents proxy API keys from leaking into logs when
KeysManagementClient.info()fails. That method puts the lookup key in the query string;requestserror text and exception chains previously echoed the full URL.info()now runs failures through always-onredact_string, raises redactedUnauthorizedError/HTTPErrorwithfrom Noneso the unredacted original is not chained, and keeps the originalresponsefor status/body.UnauthorizedErrorandNotFoundErrorscruborig_exceptionthe same way via_redact_orig_exception.Regression tests assert the key is absent from
str(exc),orig_exception, and rendered tracebacks.exc.response.request.urlmay still contain the key (documented residual; server-side LIT-4013).Reviewed by Cursor Bugbot for commit 366eb06. Bugbot is set up for automated code reviews on this repo. Configure here.