mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-15 10:14:32 +00:00
Key cached MCP clients by a digest of the whole token
The cache key held the first ten characters of a bearer token or API key. Every fine-grained GitHub token starts with github_pat_, so two users of the same server shared one cached client, and with it the first user's token, for up to five minutes.
This commit is contained in:
1 parent
f4397a7a65
commit
35d6d80e87
2 files changed
+30
-2
No files matched your search
@@ -266,6 +266,23 @@ class TestGenerateCacheKey:
|
||||
})
|
||||
assert "apikey:none" in tool._cache_key
|
||||
|
||||
@pytest.mark.parametrize("auth_type, field", [("bearer", "bearer_token"), ("api_key", "api_key")])
|
||||
def test_tokens_with_a_shared_prefix_get_their_own_client(self, auth_type, field):
|
||||
"""Every fine-grained GitHub token starts with ``github_pat_``; two users' tokens
|
||||
must never share a cached client (it carries the first user's token)."""
|
||||
first = _make_tool({
|
||||
"server_url": "https://mcp.example.com",
|
||||
"auth_type": auth_type,
|
||||
"auth_credentials": {field: "github_pat_11AAAAAAA_alice"},
|
||||
})
|
||||
second = _make_tool({
|
||||
"server_url": "https://mcp.example.com",
|
||||
"auth_type": auth_type,
|
||||
"auth_credentials": {field: "github_pat_11AAAAAAA_bob"},
|
||||
})
|
||||
assert first._cache_key != second._cache_key
|
||||
assert "github_pat" not in first._cache_key
|
||||
|
||||
|
||||
# =====================================================================
|
||||
# Transport Creation
|
||||
|
||||
Reference in new issue
Block a user