Skip to content

Commit 55811b5

Browse files
committed
security: Replace weak MD5 hash with SHA256 in MCPSessionManager
Replaces `hashlib.md5` with `hashlib.sha256` for session key generation in `mcp_session_manager.py` to mitigate security risks associated with weak cryptographic hashes. Updated the corresponding unit test to expect SHA256 hashes.
1 parent 25933a8 commit 55811b5

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/google/adk/tools/mcp_tool/mcp_session_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _generate_session_key(
273273
# For SSE and StreamableHTTP connections, use merged headers
274274
if merged_headers:
275275
headers_json = json.dumps(merged_headers, sort_keys=True)
276-
headers_hash = hashlib.md5(headers_json.encode()).hexdigest()
276+
headers_hash = hashlib.sha256(headers_json.encode()).hexdigest()
277277
return f'session_{headers_hash}'
278278
else:
279279
return 'session_no_headers'

tests/unittests/tools/mcp_tool/test_mcp_session_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_generate_session_key_sse(self):
222222

223223
# Should be deterministic hash
224224
headers_json = json.dumps(headers1, sort_keys=True)
225-
expected_hash = hashlib.md5(headers_json.encode()).hexdigest()
225+
expected_hash = hashlib.sha256(headers_json.encode()).hexdigest()
226226
assert key1 == f"session_{expected_hash}"
227227

228228
def test_merge_headers_stdio(self):

0 commit comments

Comments
 (0)