Skip to content

Self-improving AI Employees for everyone

security: keep credential-derived bytes out of the client cache-key hash

trohitg6cd159871cd7
diff --git a/server/services/llm/unifier.py b/server/services/llm/unifier.py
index ea323896..e3009c83 100644
--- a/server/services/llm/unifier.py
+++ b/server/services/llm/unifier.py
@@ -354,20 +354,25 @@ class ChatUnifier:
proxy_url: Optional[str],
sdk_max_retries: int,
) -> str:
- credential_fingerprint = fingerprint_credential(api_key)
material = json.dumps(
{
"provider": spec.name,
"proxy_url": proxy_url or "",
"client_kwargs": spec.client_kwargs,
- "credential": credential_fingerprint,
"max_retries": max(0, int(sdk_max_retries)),
},
sort_keys=True,
separators=(",", ":"),
default=str,
)
- return hashlib.sha256(material.encode("utf-8")).hexdigest()
+ # The credential component is appended as a PBKDF2 fingerprint rather
+ # than folded into the SHA-256 material: credential-derived bytes must
+ # never enter a fast hash (CodeQL py/weak-sensitive-data-hashing).
+ return (
+ hashlib.sha256(material.encode("utf-8")).hexdigest()
+ + ":"
+ + fingerprint_credential(api_key)
+ )
@staticmethod
async def _close_client(client: LLMProvider) -> None:
diff --git a/server/tests/conftest.py b/server/tests/conftest.py
index 0bf4d9bd..ec39984a 100644
--- a/server/tests/conftest.py
+++ b/server/tests/conftest.py
@@ -121,6 +121,18 @@ sys.modules["core.auth_cookies"] = _auth_cookies_mod
_auth_cookies_spec.loader.exec_module(_auth_cookies_mod)
setattr(_core_pkg, "auth_cookies", _auth_cookies_mod)
+# core.encryption depends only on stdlib + cryptography, and its
+# fingerprint_credential is imported at module load by services.llm.unifier
+# and services.memory.vector_store, so expose the real module.
+_encryption_spec = _importlib_util.spec_from_file_location(
+ "core.encryption",
+ SERVER_DIR / "core" / "encryption.py",
+)
+_encryption_mod = _importlib_util.module_from_spec(_encryption_spec)
+sys.modules["core.encryption"] = _encryption_mod
+_encryption_spec.loader.exec_module(_encryption_mod)
+setattr(_core_pkg, "encryption", _encryption_mod)
+
# core.paths — central path resolution. Stub the public surface with
# tmpdir-rooted Paths so plugin module imports don't trip over the
# real ``Path.home()`` lookup during test collection. Tests that