Repository navigation
fix(redaction): scrub authorization_token values by their key name - #53740
yujonglee-berri merged 1 commit into
Conversation
|
@greptileai please review this PR. It is stacked, so compare it with its base branch and not with main. |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
[Medium impact] The PR appears safe to merge with no actionable issues found.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
8545db2 to
31ec4f8
Compare
|
@greptileai this PR gained a second change in 31ec4f8e06e, an auth scheme in the key name pattern. Please review the new commit. |
31ec4f8 to
9efa76c
Compare
|
@greptileai this PR was restacked to 9efa76c4a27 with no change of its own. Please review the current head against its base branch. |
9efa76c to
856a1af
Compare
|
@greptileai this PR was restacked to 856a1af32f1 with no change of its own. Please review the current head against its base branch. |
An MCP server entry in a /v1/messages request carries its credential as authorization_token. The key name list both redactors share had auth_token, access_token and refresh_token but not this one, so an opaque token under it stayed in debug logs. It is added to the Python list and to the Rust list, which must agree. A value under one of these key names may start with an auth scheme, as in Bearer abc. The key name pattern took the value up to the first space, so it hid the scheme and left the credential. It now takes a Bearer or Basic scheme together with the value.
856a1af to
b130f5d
Compare
|
@greptileai this PR was restacked to b130f5d with no change of its own. Please review the current head against its base branch. |
surlymochan
left a comment
There was a problem hiding this comment.
Verified the Python pattern by running it locally (compiled with re.IGNORECASE, as at secret_redaction.py:90): Bearer, lowercase bearer, and Basic all redact the whole value under authorization_token, and a bare authorization_token value redacts too. authorization_note does not match, so there is no false positive on the key prefix. The Python and Rust patterns were changed in lockstep, and the new tests cover both backends (native False/True) plus the structured-value path. This closes the MCP credential leak in logs.
…53740) An MCP server entry in a /v1/messages request carries its credential as authorization_token. The key name list both redactors share had auth_token, access_token and refresh_token but not this one, so an opaque token under it stayed in debug logs. It is added to the Python list and to the Rust list, which must agree. A value under one of these key names may start with an auth scheme, as in Bearer abc. The key name pattern took the value up to the first space, so it hid the scheme and left the credential. It now takes a Bearer or Basic scheme together with the value. (cherry picked from commit f409bfd)
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
Problem this solves:
authorization_tokenstayed readable in debug logsHow it solves it:
authorization_tokenis added to the key name list in PythonBearerorBasicscheme in front of such a value is hidden with itIntentional product change: a value under the key
authorization_tokennow shows asREDACTEDin log lines. Nothing else about a line changes.User Flow
Before: an operator debugging the gateway finds a client's MCP server token in its log
mcp_serversentry whoseauthorization_tokenisopaque-mcp-credentialRUST_LOG=debugand logs the request bodybody chunklog line shows"authorization_token":"opaque-mcp-credential"After: the same request leaves no token in the log
RUST_LOG=debugand logs the request bodybody chunklog line shows"authorization_token":"REDACTED"Relevant issues
Top of the stack over #53690, #53539, #53709, #53713, #53714, #53717, #53738 and #53739. It answers a review finding on #53714.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays 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
The flow is one real
/v1/messagescall through the standalone gateway binary to Anthropic, with the gateway's stderr saved as its log, and one call to Python's redactor. Anthropic answers 400 in both runs, because the request names an MCP server and no tool uses it. The gateway logs the request body before it calls the provider, so the log line under test is written either way.Three tests cover the list.
test_an_mcp_authorization_token_is_redacted_by_its_key_nameintests/unit/test_secret_redaction.pyruns against the Python redactor and the Rust one, and checks that a key that only starts the same way,authorization_note, is left alone.redacts_the_same_spans_as_the_python_patternsincrates/redaction/src/secret.rshas a new case, anda_scrubbed_sink_scrubs_a_logged_json_body_value_by_valueincrates/tracing/tests/logging.rschecks the token inside a logged body. All three failed before the change.test_a_value_with_an_auth_scheme_is_redacted_whole_under_a_secret_key_namecovers"authorization_token": "Bearer ..."in text that is not a JSON document, for both redactors. Without the scheme in the pattern it printed"REDACTED opaque-mcp-credential", which a review found on this PR's first version.Shared setup, from the repo root, with
ANTHROPIC_API_KEYexported.Before (2acd262a060)
python -c "... redact_secrets(...)"curl ... /v1/messagesgrep -c 'opaque-mcp-credential' gateway.log, then thechunkfield of the request'sbody chunklineAfter (31ec4f8e06e, tip b130f5d)
python -c "... redact_secrets(...)"curl ... /v1/messagesgrep -c 'opaque-mcp-credential' gateway.log, then thechunkfield of the request'sbody chunklineType
🐛 Bug Fix
Caveats (if any)
Low
auth_tokenandaccess_tokenBearer abcunder them was half hidden before, and is fully hidden nowFinal Attestation