[Bugfix][Frontend] Redact hf_token in the non-default args log (#53625)
Signed-off-by: mhuzaifa3 <mhuzaifa3@outlook.com>
This commit is contained in:
@@ -120,11 +120,19 @@ class TestRedactSensitiveArgs:
|
|||||||
API_KEY = "sk-test-secret-12345"
|
API_KEY = "sk-test-secret-12345"
|
||||||
|
|
||||||
def test_redact_replaces_sensitive_values_only(self):
|
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)
|
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
|
# 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):
|
def test_no_sensitive_fields_returns_original(self):
|
||||||
args = {"model_tag": "org/model", "other": "visible"}
|
args = {"model_tag": "org/model", "other": "visible"}
|
||||||
@@ -147,3 +155,18 @@ class TestRedactSensitiveArgs:
|
|||||||
# non-sensitive args are still logged
|
# non-sensitive args are still logged
|
||||||
assert "org/model" in message
|
assert "org/model" in message
|
||||||
assert "qwen3_coder" 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
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ def jsonify_non_default_args(
|
|||||||
|
|
||||||
|
|
||||||
# Fields whose values must never be logged verbatim.
|
# 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]:
|
def _redact_sensitive_args(args: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
|||||||
Reference in New Issue
Block a user