[Fix] Redact JWT bearer tokens in debug logs#22314
Open
shivamrawat1 wants to merge 2 commits intomainfrom
Open
[Fix] Redact JWT bearer tokens in debug logs#22314shivamrawat1 wants to merge 2 commits intomainfrom
shivamrawat1 wants to merge 2 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR adds a
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/_logging.py | Adds SensitiveLogFilter class and regex to redact Bearer tokens from log messages. Filter correctly attached to all named loggers and root logger. One concern: bare except could silently skip redaction on format errors. |
| tests/test_litellm/test_logging.py | Comprehensive unit tests for SensitiveLogFilter covering plain messages, dict format args, case insensitivity, multiple tokens, edge cases, and arg clearing. All tests are properly mocked with no network calls. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Log call: verbose_logger.debug(msg, args)"] --> B["SensitiveLogFilter.filter()"]
B --> C{"record.getMessage()\nsucceeds?"}
C -->|Yes| D{"Bearer token\nfound in message?"}
C -->|No| H["except: pass\n(token may leak)"]
D -->|Yes| E["Regex sub: Bearer [REDACTED]"]
E --> F["record.args = None"]
D -->|No| G["Record unchanged"]
F --> I["return True → Handler/Formatter"]
G --> I
H --> I
Last reviewed commit: 193fe54
Collaborator
Author
|
@greptile re-review now that we have added the sensitive filter in the root logger as asked with the new commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
With --detailed_debug, JWT bearer tokens from the Authorization header were logged in full. This exposed credentials in server output, log files, and any log aggregation systems.
The proxy stores raw request headers (including Authorization) in data["secret_fields"] for MCP and response forwarding. Several debug log calls (e.g. print_args_passed_to_litellm in utils.py and the "receiving data" logs in litellm_pre_call_utils.py and proxy_server.py) logged the full data or kwargs without redacting these fields.

Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
✅ Test
Changes
A SensitiveLogFilter was added in litellm/_logging.py and attached to all three LiteLLM loggers. It runs before any handler and redacts Bearer tokens in the formatted log message using a regex, replacing them with Bearer [REDACTED]. This centralizes redaction so new log sites are covered without per-call changes.