Add usedforsecurity=False to non-security hashlib calls

MD5 in bambu_mqtt.py is used for AMS tray change detection fingerprinting,
and SHA1 in github_backup.py matches Git's blob hash format. Neither is
used for security purposes, so mark them explicitly to satisfy Bandit B303
and CodeQL py/weak-cryptographic-algorithm findings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
maziggy
2026-02-06 11:15:26 +01:00
co-authored by Claude Opus 4.6
parent dc82b5ff2a
commit 91662d9c5d
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -1053,7 +1053,7 @@ class BambuMQTTClient:
f"{ams_unit.get('id')}:{tray.get('id')}:"
f"{tray.get('tray_type')}:{tray.get('tag_uid')}:{tray.get('remain')}"
)
ams_hash = hashlib.md5(":".join(ams_hash_data).encode()).hexdigest()
ams_hash = hashlib.md5(":".join(ams_hash_data).encode(), usedforsecurity=False).hexdigest()
# Only trigger callback if AMS data actually changed
if ams_hash != self._previous_ams_hash:
+3 -1
View File
@@ -535,7 +535,9 @@ class GitHubBackupService:
for path, content in files.items():
content_str = json.dumps(content, indent=2, default=str)
content_bytes = content_str.encode("utf-8")
content_sha = hashlib.sha1(f"blob {len(content_bytes)}\0".encode() + content_bytes).hexdigest()
content_sha = hashlib.sha1(
f"blob {len(content_bytes)}\0".encode() + content_bytes, usedforsecurity=False
).hexdigest()
# Skip if file hasn't changed
if path in existing_files and existing_files[path] == content_sha: