Skip to content

Commit 10287c5

Browse files
authored
Merge pull request #88 from ddulic/fix/md5-usedforsecurity-false
fix(security): add usedforsecurity=False to all hashlib.md5 calls
2 parents 936d666 + c8d9bdb commit 10287c5

7 files changed

Lines changed: 10 additions & 10 deletions

File tree

supernote/cli/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def add_user_async(
3636

3737
# Hash password
3838
_warn_md5_usage()
39-
password_md5 = hashlib.md5(password.encode()).hexdigest()
39+
password_md5 = hashlib.md5(password.encode(), usedforsecurity=False).hexdigest()
4040

4141
# Try Public Registration
4242
try:
@@ -123,7 +123,7 @@ async def reset_password_async(url: str, email: str, password: str) -> None:
123123
admin_client = AdminClient(session.client)
124124

125125
_warn_md5_usage()
126-
password_md5 = hashlib.md5(password.encode()).hexdigest()
126+
password_md5 = hashlib.md5(password.encode(), usedforsecurity=False).hexdigest()
127127

128128
try:
129129
await admin_client.admin_reset_password(email, password_md5)

supernote/client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async def _upload_to_oss(
281281
raise ValueError("No upload URL available")
282282

283283
# Compute MD5 of content for verification
284-
content_md5 = hashlib.md5(content).hexdigest()
284+
content_md5 = hashlib.md5(content, usedforsecurity=False).hexdigest()
285285

286286
_LOGGER.debug(
287287
"Uploading file %s in one chunk (MD5: %s)", filename, content_md5
@@ -324,7 +324,7 @@ async def _upload_to_oss(
324324
# Break into chunks
325325
chunks = [content[i : i + chunk_size] for i in range(0, size, chunk_size)]
326326
for i, chunk in enumerate(chunks):
327-
chunk_md5 = hashlib.md5(chunk).hexdigest()
327+
chunk_md5 = hashlib.md5(chunk, usedforsecurity=False).hexdigest()
328328
_LOGGER.debug(f"Uploading chunk {i + 1} of {size} ({len(chunk)} bytes)")
329329
data = FormData()
330330
data.add_field("file", chunk, filename=filename)

supernote/client/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async def upload_content(
173173
_LOGGER.debug("Initiating upload for file %s", path)
174174
apply = await self.upload_apply(filename, path, size, equipment_no)
175175

176-
md5 = hashlib.md5(content).hexdigest()
176+
md5 = hashlib.md5(content, usedforsecurity=False).hexdigest()
177177

178178
await self._client._upload_to_oss(
179179
content,

supernote/client/hashing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _md5_string(s: str) -> str:
3535
Security Warning: MD5 is cryptographically broken but required for Supernote protocol compatibility.
3636
"""
3737
_warn_md5_usage()
38-
return hashlib.md5(s.encode("utf-8")).hexdigest()
38+
return hashlib.md5(s.encode("utf-8"), usedforsecurity=False).hexdigest()
3939

4040

4141
def hash_with_salt(content: str, salt: str) -> str:

supernote/client/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async def folder_list_query(
177177

178178
async def upload_file(self, parent_id: int, name: str, content: bytes) -> None:
179179
"""Upload a file (Web API)."""
180-
md5 = hashlib.md5(content).hexdigest()
180+
md5 = hashlib.md5(content, usedforsecurity=False).hexdigest()
181181
size = len(content)
182182

183183
# Apply to get an upload endpoint

supernote/server/services/blob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def put(
106106
temp_path = temp_dir / f"{secrets.token_hex(8)}.tmp"
107107

108108
total_size = 0
109-
md5_hasher = hashlib.md5()
109+
md5_hasher = hashlib.md5(usedforsecurity=False)
110110

111111
try:
112112
async with aiofiles.open(temp_path, "wb") as f:
@@ -191,7 +191,7 @@ async def get_metadata(
191191
return BlobMetadata(size=stat.st_size)
192192

193193
# Compute MD5 and size
194-
md5_hasher = hashlib.md5()
194+
md5_hasher = hashlib.md5(usedforsecurity=False)
195195
read_size = 0
196196
async with aiofiles.open(path, "rb") as f:
197197
while True:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)