Skip to content

Commit 1ba4f20

Browse files
sfc-gh-fpawlowskisfc-gh-pczajka
authored andcommitted
SNOW-2743401: added usedforsecurity argument to md5 hash for multipart upload (#2647)
1 parent 8969d6d commit 1ba4f20

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

.github/workflows/build_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ jobs:
329329
strategy:
330330
fail-fast: false
331331
matrix:
332-
cloud-provider: [aws]
332+
cloud-provider: [aws, azure, gcp]
333333
steps:
334334
- uses: actions/checkout@v4
335335
- name: Setup parameters file

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
99
# Release Notes
1010
- v3.18.1(July 15,2026)
1111
- Improved verification of TLS connections (SNOW-3675579).
12+
- Fixed FIPS environments md5 hash issues with multipart upload on Azure.
1213

1314
- v3.18.0(October 03,2025)
1415
- Added support for pandas conversion for Day-time and Year-Month Interval types

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)