Skip to content

fix(redaction): scrub authorization_token values by their key name - #53740

Merged
yujonglee-berri merged 1 commit into
litellm_tracing_crate_trimsfrom
litellm_scrub_authorization_token
Nov 23, 2026
Merged

yujonglee-berri merged 1 commit into
litellm_tracing_crate_trimsfrom
litellm_scrub_authorization_token

Conversation

@yujonglee-berri

@yujonglee-berri yujonglee-berri commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

  • An MCP server's authorization_token stayed readable in debug logs
  • The shared list of secret key names did not include it
  • Python's redactor and the Rust one both missed it

How it solves it:

  • authorization_token is added to the key name list in Python
  • The same key is added to the Rust list, which must agree
  • The gateway's log scrubber picks it up through that list
  • A Bearer or Basic scheme in front of such a value is hidden with it

Intentional product change: a value under the key authorization_token now shows as REDACTED in 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

  1. A client sends POST http://127.0.0.1:4311/v1/messages with an mcp_servers entry whose authorization_token is opaque-mcp-credential
  2. The gateway runs with RUST_LOG=debug and logs the request body
  3. The body chunk log line shows "authorization_token":"opaque-mcp-credential"

After: the same request leaves no token in the log

  1. The client sends the same POST http://127.0.0.1:4311/v1/messages
  2. The gateway runs with RUST_LOG=debug and logs the request body
  3. The body chunk log 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings 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

The flow is one real /v1/messages call 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_name in tests/unit/test_secret_redaction.py runs 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_patterns in crates/redaction/src/secret.rs has a new case, and a_scrubbed_sink_scrubs_a_logged_json_body_value_by_value in crates/tracing/tests/logging.rs checks 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_name covers "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_KEY exported.

# config.yaml
model_list:
  - model_name: claude-haiku
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
LITELLM_RUST=0 python -c "
from litellm._logging import redact_secrets
print(redact_secrets('{\"mcp_servers\": [{\"name\": \"docs\", \"authorization_token\": \"opaque-mcp-credential\"}]}'))"
cargo build --manifest-path litellm/rust/Cargo.toml -p litellm-gateway
export LITELLM_MASTER_KEY=sk-gateway-proof-1234567890abcdef
LITELLM_CONFIG=config.yaml HOST=127.0.0.1 PORT=4311 RUST_LOG=debug litellm/rust/target/debug/litellm-gateway 2> gateway.log &
curl -sS -w "HTTP %{http_code}\n" http://127.0.0.1:4311/v1/messages \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' -H 'anthropic-beta: mcp-client-2026-09-15' \
  -d '{"model":"claude-haiku","max_tokens":20,"mcp_servers":[{"type":"url","url":"https://mcp.example.com/sse","name":"docs","authorization_token":"opaque-mcp-credential"}],"messages":[{"role":"user","content":"Reply with the single word OK."}]}'
grep -c 'opaque-mcp-credential' gateway.log

Before (2acd262a060)

  1. python -c "... redact_secrets(...)"
{"mcp_servers": [{"name": "docs", "authorization_token": "opaque-mcp-credential"}]}
  1. curl ... /v1/messages
HTTP 400
{"type":"error","error":{"type":"invalid_request_error","message":"MCP server 'docs' is defined but not referenced by any `mcp_toolset` in `tools`."},"request_id":"req_011ChKPKphr1Y7qJeGmeKxqf"}
  1. grep -c 'opaque-mcp-credential' gateway.log, then the chunk field of the request's body chunk line
1
{"model":"claude-haiku","max_tokens":20,"mcp_servers":[{"type":"url","url":"https://mcp.example.com/sse","name":"docs","authorization_token":"opaque-mcp-credential"}],"messages":[{"role":"user","content":"Reply with the single word OK."}]}

After (31ec4f8e06e, tip b130f5d)

  1. python -c "... redact_secrets(...)"
{"mcp_servers": [{"name": "docs", "REDACTED"}]}
  1. curl ... /v1/messages
HTTP 400
{"type":"error","error":{"type":"invalid_request_error","message":"MCP server 'docs' is defined but not referenced by any `mcp_toolset` in `tools`."},"request_id":"req_011ChKQMEtHxvf91VP1ceBCj"}
  1. grep -c 'opaque-mcp-credential' gateway.log, then the chunk field of the request's body chunk line
0
{"model":"claude-haiku","max_tokens":20,"mcp_servers":[{"type":"url","url":"https://mcp.example.com/sse","name":"docs","authorization_token":"REDACTED"}],"messages":[{"role":"user","content":"Reply with the single word OK."}]}

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The live run covers the gateway's log, not a Python proxy's
    • Python is covered by the redactor call above and by the unit test
  • No successful MCP request was sent
    • The provider answered 400 in both runs, which does not change what the gateway logs
  • A key name the list does not hold is still not hidden by its name
  • The tip only moved onto a restacked base
    • Its own diff is the same as at the tested 31ec4f8e06e, and its tests were rerun at the tip
  • The before run used the gateway built at 2acd262a060
    • The stack was restacked since, with no change to how a request body is scrubbed
  • The scheme change reaches every key name in that list, such as auth_token and access_token
    • A value like Bearer abc under them was half hidden before, and is fully hidden now

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Devin Review

@veria-ai

veria-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai please review this PR. It is stacked, so compare it with its base branch and not with main.

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

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge with no actionable issues found.

Summary

Adds authorization_token to the secret-key patterns in Python and Rust. Both patterns also hide a leading Bearer or Basic scheme with the value.

Regression tests cover both redactor paths and nested gateway log bodies. No actionable issues found against the current base. Tests were inspected, not run.

  • Redactors now hide MCP tokens named authorization_token.

Reviews (5) · Last reviewed commit: "fix(redaction): scrub authorization_toke..." · Reviewed by Greptile

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yujonglee-berri
yujonglee-berri force-pushed the litellm_scrub_authorization_token branch from 8545db2 to 31ec4f8 Compare November 23, 2026 06:41
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai this PR gained a second change in 31ec4f8e06e, an auth scheme in the key name pattern. Please review the new commit.

@yujonglee-berri
yujonglee-berri force-pushed the litellm_scrub_authorization_token branch from 31ec4f8 to 9efa76c Compare November 23, 2026 06:57
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai this PR was restacked to 9efa76c4a27 with no change of its own. Please review the current head against its base branch.

@yujonglee-berri yujonglee-berri added the autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review. label Nov 23, 2026
@yujonglee-berri
yujonglee-berri force-pushed the litellm_scrub_authorization_token branch from 9efa76c to 856a1af Compare November 23, 2026 07:08
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@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.
@yujonglee-berri
yujonglee-berri force-pushed the litellm_scrub_authorization_token branch from 856a1af to b130f5d Compare November 23, 2026 07:24
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

@greptileai this PR was restacked to b130f5d with no change of its own. Please review the current head against its base branch.

@surlymochan surlymochan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Approving per the autoapprove label. Greptile scored the current head 5/5, but its auto-approval doesn't fire on stacked PRs whose base isn't main.

@yujonglee-berri
yujonglee-berri merged commit f409bfd into main Nov 23, 2026
140 of 180 checks passed
@yujonglee-berri
yujonglee-berri deleted the litellm_scrub_authorization_token branch November 23, 2026 08:54
mateo-berri pushed a commit that referenced this pull request Nov 25, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review. rust-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants