Skip to content

Commit 1680c6c

Browse files
SNOW-2743401: added usedforsecurity argument to md5 hash for multipart upload (snowflakedb#2647)
1 parent 271e6ca commit 1680c6c

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.github/workflows/build_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ jobs:
335335
strategy:
336336
fail-fast: false
337337
matrix:
338-
cloud-provider: [aws]
338+
cloud-provider: [aws, azure, gcp]
339339
steps:
340340
- uses: actions/checkout@v4
341341
- name: Setup parameters file

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1515
- Added no_proxy parameter for proxy configuration without using environmental variables.
1616
- Added OAUTH_AUTHORIZATION_CODE and OAUTH_CLIENT_CREDENTIALS to list of authenticators that don't require user to be set
1717
- Added `oauth_socket_uri` connection parameter allowing to separate server and redirect URIs for local OAuth server.
18+
- Fixed FIPS environments md5 hash isues with multipart upload on Azure.
1819

1920
- v4.0.0(October 09,2025)
2021
- Added support for checking certificates revocation using revocation lists (CRLs)

src/snowflake/connector/azure_storage_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .constants import FileHeader, ResultStatus
1515
from .encryption_util import EncryptionMetadata
1616
from .storage_client import SnowflakeStorageClient
17-
from .util_text import get_md5
17+
from .util_text import get_md5_for_integrity
1818
from .vendored import requests
1919

2020
if TYPE_CHECKING: # pragma: no cover
@@ -241,9 +241,9 @@ def _complete_multipart_upload(self) -> None:
241241
fd.close()
242242
headers = {
243243
"x-ms-blob-content-encoding": "utf-8",
244-
"x-ms-blob-content-md5": base64.b64encode(get_md5(file_content)).decode(
245-
"utf-8"
246-
),
244+
"x-ms-blob-content-md5": base64.b64encode(
245+
get_md5_for_integrity(file_content)
246+
).decode("utf-8"),
247247
}
248248
azure_metadata = self._prepare_file_metadata()
249249
headers.update(azure_metadata)

src/snowflake/connector/util_text.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,11 @@ def _base64_bytes_to_str(x) -> str | None:
293293
return base64.b64encode(x).decode("utf-8") if x else None
294294

295295

296-
def get_md5(text: str | bytes) -> bytes:
296+
def get_md5_for_integrity(text: str | bytes) -> bytes:
297+
# MD5 should not be used for security reasons - only integrity is safe and allowed
297298
if isinstance(text, str):
298299
text = text.encode("utf-8")
299-
md5 = hashlib.md5()
300+
# Usedforsecurity=False added to support FIPS envs as well
301+
md5 = hashlib.md5(usedforsecurity=False)
300302
md5.update(text)
301303
return md5.digest()

0 commit comments

Comments
 (0)