Skip to content

Commit 205b1b2

Browse files
security: pseudonymize credential rate-limit identity with HMAC
1 parent cb6c132 commit 205b1b2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎app/api/routes.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import hashlib
6+
import hmac
67
import json
78
import logging
89
import time
@@ -102,7 +103,9 @@ def _rate_limit_identity(api_key: str | None) -> str:
102103

103104
if api_key is None:
104105
return "development-anonymous"
105-
return hashlib.sha256(api_key.encode("utf-8")).hexdigest()
106+
return hmac.new(
107+
api_key.encode("utf-8"), b"deepsequence-rate-limit-identity:v1", hashlib.sha256
108+
).hexdigest()
106109

107110

108111
def _response(

0 commit comments

Comments
 (0)