mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-08-11 00:42:48 +00:00
fix: clear CodeQL weak sensitive hashing on model catalog cache key
SHA-256 of API key material in _cache_key trips py/weak-sensitive-data-hashing (CodeQL alert #64). Use HMAC-SHA256 with the credential as the key and a fixed app message so the cache partition id stays non-reversible without password-style hashing. Co-authored-by: Rip&Tear <theCyberTech@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import time
|
||||
|
||||
@@ -583,6 +585,14 @@ def test_cache_key_hashes_key_and_never_stores_it(monkeypatch):
|
||||
key = mc._cache_key("openai")
|
||||
assert key.startswith("openai#") and key != "openai#nokey"
|
||||
assert "sk-super-secret" not in key # only a digest, never the raw key
|
||||
# Credential is the HMAC key (not SHA-256 hash input) so CodeQL
|
||||
# py/weak-sensitive-data-hashing does not flag password-style hashing.
|
||||
expected = hmac.new(
|
||||
b"sk-super-secret",
|
||||
b"crewai.model_catalog.cache_v1",
|
||||
hashlib.sha256,
|
||||
).hexdigest()[:12]
|
||||
assert key == f"openai#{expected}"
|
||||
|
||||
|
||||
def test_dynamic_cache_expires_after_catalog_ttl(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user