Skip to content

Commit a5ab857

Browse files
committed
Fix bandit security warnings for SHA1 hash usage
Add usedforsecurity=False parameter to hashlib.sha1() calls. SHA1 is used for query fingerprinting, not cryptographic security, so this parameter correctly indicates the usage and resolves the bandit B324 warnings.
1 parent 6511400 commit a5ab857

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

graphql_sqlcommenter/graphene_integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ def _generate_document_hash(query: str, length: int = 10) -> str:
468468
Returns:
469469
A hex-encoded hash of the query
470470
"""
471-
return hashlib.sha1(query.encode("utf-8")).hexdigest()[:length]
471+
return hashlib.sha1(query.encode("utf-8"), usedforsecurity=False).hexdigest()[
472+
:length
473+
]
472474

473475

474476
def _coerce_query_string(source: str | Any) -> str:

graphql_sqlcommenter/middleware.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def _generate_document_hash(self, query: str, length: int = 10) -> str:
142142
Returns:
143143
A hex-encoded hash of the query
144144
"""
145-
return hashlib.sha1(query.encode("utf-8")).hexdigest()[:length]
145+
return hashlib.sha1(query.encode("utf-8"), usedforsecurity=False).hexdigest()[
146+
:length
147+
]
146148

147149
def _parse_body(self, body: str) -> Mapping[str, object]:
148150
"""

0 commit comments

Comments
 (0)