fix(mcp): redact credentials from URLs before logging
MCP server URLs can carry secrets in userinfo (`https://user:token@host/sse`) or a query string (`?token=...`). A few connect/validate paths logged the raw `cfg.url` / `request.url`, so those secrets could land in log files that are often shared or aggregated. Add a small `_redact_url()` helper that keeps only scheme/host/port/path and use it at the four sites that log a server or request URL. Logging only; no other behavior changes.
This commit is contained in:
committed by
Xubin Ren
parent
1873e948c3
commit
780093d037
@@ -1240,3 +1240,15 @@ async def test_connect_mcp_servers_enabled_tools_matches_sanitized_name(
|
||||
await stack.aclose()
|
||||
|
||||
assert registry.tool_names == ["mcp_test_My_Tool"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url, expected",
|
||||
[
|
||||
("https://user:secret@host.example/sse", "https://host.example/sse"),
|
||||
("https://host.example:8443/mcp?token=abc#frag", "https://host.example:8443/mcp"),
|
||||
("https://host.example/sse", "https://host.example/sse"),
|
||||
],
|
||||
)
|
||||
def test_redact_url_strips_credentials_and_query(url: str, expected: str) -> None:
|
||||
assert mcp_mod._redact_url(url) == expected
|
||||
|
||||
Reference in New Issue
Block a user