[Bugfix][Frontend] Redact hf_token in the non-default args log (#53625)

Signed-off-by: mhuzaifa3 <mhuzaifa3@outlook.com>
This commit is contained in:
Moe Huzaifa
2026-08-25 03:06:46 +00:00
committed by GitHub
parent b2dd9ce73d
commit d3e2888c75
2 changed files with 27 additions and 4 deletions
@@ -120,11 +120,19 @@ class TestRedactSensitiveArgs:
API_KEY = "sk-test-secret-12345"
def test_redact_replaces_sensitive_values_only(self):
args = {"api_key": self.API_KEY, "other": "visible"}
args = {"api_key": self.API_KEY, "hf_token": "hf_secret", "other": "visible"}
redacted = _redact_sensitive_args(args)
assert redacted == {"api_key": "***", "other": "visible"}
assert redacted == {
"api_key": "***",
"hf_token": "***",
"other": "visible",
}
# original dict must not be mutated
assert args == {"api_key": self.API_KEY, "other": "visible"}
assert args == {
"api_key": self.API_KEY,
"hf_token": "hf_secret",
"other": "visible",
}
def test_no_sensitive_fields_returns_original(self):
args = {"model_tag": "org/model", "other": "visible"}
@@ -147,3 +155,18 @@ class TestRedactSensitiveArgs:
# non-sensitive args are still logged
assert "org/model" in message
assert "qwen3_coder" in message
def test_hf_token_not_in_log(self, monkeypatch, caplog):
hf_token = "hf_TESTTOKENVALUE123"
non_default = {
"model_tag": "org/model",
"hf_token": hf_token,
"tool_call_parser": "qwen3_coder",
}
monkeypatch.setattr(api_utils, "get_non_default_args", lambda args: non_default)
with caplog.at_level("INFO", logger="vllm.entrypoints.serve.utils.api_utils"):
api_utils.log_non_default_args(args=Namespace())
message = caplog.text
assert hf_token not in message
assert "'hf_token': '***'" in message
assert "org/model" in message
+1 -1
View File
@@ -268,7 +268,7 @@ def jsonify_non_default_args(
# Fields whose values must never be logged verbatim.
_SENSITIVE_ARG_FIELDS = frozenset({"api_key"})
_SENSITIVE_ARG_FIELDS = frozenset({"api_key", "hf_token"})
def _redact_sensitive_args(args: dict[str, Any]) -> dict[str, Any]: