Skip to content

[Feat] Add token redaction for logger debug - #824

Merged
ruizhang0101 merged 8 commits into
vllm-project:mainfrom
shernshiou:feat/token_redaction
Feb 17, 2026
Merged

ruizhang0101 merged 8 commits into
vllm-project:mainfrom
shernshiou:feat/token_redaction

Conversation

@shernshiou

Copy link
Copy Markdown
Contributor

This PR implements a new feature to redact the token by default
If the user set disable_token_redaction to True, the redaction will be skipped.

FIX #819

BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE


  • Make sure the code changes pass the pre-commit checks.
  • Sign-off your commit by using -s when doing git commit
  • Try to classify PRs for easy understanding of the type of changes, such as [Bugfix], [Feat], and [CI].
Detailed Checklist (Click to Expand)

Thank you for your contribution to production-stack! Before submitting the pull request, please ensure the PR meets the following criteria. This helps us maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Please try to classify PRs for easy understanding of the type of changes. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Feat] for new features in the cluster (e.g., autoscaling, disaggregated prefill, etc.).
  • [Router] for changes to the vllm_router (e.g., routing algorithm, router observability, etc.).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • Pass all linter checks. Please use pre-commit to format your code. See README.md for installation.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Please include sufficient tests to ensure the change is stay correct and robust. This includes both unit tests and integration tests.

DCO and Signed-off-by

When contributing changes to this project, you must agree to the DCO. Commits must include a Signed-off-by: header which certifies agreement with the terms of the DCO.

Using -s with git commit will automatically add this header.

What to Expect for the Reviews

We aim to address all PRs in a timely manner. If no one reviews your PR within 5 days, please @-mention one of YuhanLiu11
, Shaoting-Feng or ApostaC.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shernshiou, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the security posture of the router by introducing a mechanism to redact sensitive authentication tokens and API keys from debug logs. It adds a new command-line option to disable this redaction if needed, ensuring that confidential information is not inadvertently exposed in logs while still providing the flexibility for developers to view full headers when necessary.

Highlights

  • New Configuration Option: Introduced a --disable-token-redaction command-line argument to control the redaction of sensitive information in logs.
  • Sensitive Header Redaction: Implemented a utility function to automatically redact common authentication tokens and API keys from request headers before they are logged at debug level.
  • Integration with Request Handling: The token redaction logic is now applied to request headers when they are logged for debugging purposes within the general request routing service.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/vllm_router/app.py
    • The disable_token_redaction flag, parsed from command-line arguments, is now stored in the FastAPI application state during initialization.
  • src/vllm_router/parsers/parser.py
    • Added a new command-line argument --disable-token-redaction (boolean flag, default False) to allow users to control the token redaction feature.
  • src/vllm_router/services/request_service/request.py
    • Imported the new redact_token_in_request_header utility function.
    • Modified the route_general_request function to use this utility to redact sensitive headers before logging them at the debug level, respecting the disable_token_redaction setting from the app state.
  • src/vllm_router/utils.py
    • Imported Headers from starlette.datastructures.
    • Added a new function redact_token_in_request_header which takes request headers and a disable flag. It redacts values for common sensitive headers (e.g., authorization, x-api-key) by replacing most of their content with ****, unless redaction is disabled.
Activity
  • The author has completed the pre-commit checks, ensuring code quality and formatting.
  • The commit has been signed off, indicating agreement with the Developer Certificate of Origin (DCO).
  • The pull request is classified as a [Feat] (Feature) as per the project's guidelines.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@shernshiou
shernshiou force-pushed the feat/token_redaction branch from 399b052 to d9258f1 Compare February 5, 2026 19:15

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a security enhancement to redact sensitive tokens (like API keys and authorization tokens) from request headers in debug logs by default. A new command-line argument --disable-token-redaction is added to allow disabling this feature if needed. The implementation is well-contained, with changes to argument parsing, application initialization, and a new utility function for redaction. My review includes a suggestion to optimize the new redaction utility function for better performance and code style.

Comment thread src/vllm_router/utils.py Resolved
@shernshiou

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a valuable security feature to redact sensitive tokens from debug logs by default. The implementation is mostly correct, adding a command-line flag to control this behavior and a utility function to perform the redaction. I've identified a bug in the redaction logic that could lead to the loss of headers when multiple headers with the same name are present, and I've also included a minor suggestion for a small performance improvement. Once these points are addressed, this will be a solid contribution.

Comment thread src/vllm_router/utils.py Resolved
Comment thread src/vllm_router/utils.py Resolved
@shernshiou
shernshiou marked this pull request as draft February 5, 2026 20:26
@shernshiou
shernshiou marked this pull request as ready for review February 5, 2026 21:03
@shernshiou
shernshiou force-pushed the feat/token_redaction branch 3 times, most recently from a0d164d to 62a4eba Compare February 7, 2026 06:26

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, Thanks for the contribution! I have added some suggestions, lemme know if you have any questions. :))

Comment thread src/vllm_router/parsers/parser.py Resolved
Comment thread src/vllm_router/utils.py Resolved
Comment thread src/vllm_router/utils.py Resolved
@shernshiou

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a valuable feature for redacting sensitive tokens from debug logs, which is a great step for security and observability. The implementation is well-structured and includes a comprehensive set of tests. I've identified a minor logical issue in the TokenRedactionFilter that could lead to unintended type conversions in log arguments under specific circumstances. A detailed comment with a suggested fix is provided below. With that small correction, this will be a solid addition.

Comment thread src/vllm_router/utils.py Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Shern Shiou Tan <[email protected]>

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi I have made several comments, lemme know if you have any questions :))

Comment thread src/vllm_router/utils.py Resolved

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM :))

@ruizhang0101
ruizhang0101 merged commit 5e374b0 into vllm-project:main Feb 17, 2026
15 of 16 checks passed
@NargiT NargiT mentioned this pull request Feb 20, 2026
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.

feature: Mask Bearer Tokens in Request Logs and Debug Output

2 participants