fix: handle missing hashlib.md5 on FIPS-enforced Python - #1130
fix: handle missing hashlib.md5 on FIPS-enforced Python#1130mwatkins-ld wants to merge 5 commits into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/httpx2/httpx2/_auth.py">
<violation number="1" location="src/httpx2/httpx2/_auth.py:178">
P3: The FIPS test never exercises this import-time guard; add a test that imports/reloads the auth module with `hashlib.md5` absent so the original library-import failure remains covered.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| "SHA-512": hashlib.sha512, | ||
| "SHA-512-SESS": hashlib.sha512, | ||
| } | ||
| if hasattr(hashlib, "md5"): |
There was a problem hiding this comment.
P3: The FIPS test never exercises this import-time guard; add a test that imports/reloads the auth module with hashlib.md5 absent so the original library-import failure remains covered.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/httpx2/httpx2/_auth.py, line 178:
<comment>The FIPS test never exercises this import-time guard; add a test that imports/reloads the auth module with `hashlib.md5` absent so the original library-import failure remains covered.</comment>
<file context>
@@ -168,15 +168,16 @@ def _build_auth_header(self, username: str | bytes, password: str | bytes) -> st
"SHA-512": hashlib.sha512,
"SHA-512-SESS": hashlib.sha512,
}
+ if hasattr(hashlib, "md5"):
+ _ALGORITHM_TO_HASH_FUNCTION["MD5"] = hashlib.md5
+ _ALGORITHM_TO_HASH_FUNCTION["MD5-SESS"] = hashlib.md5
</file context>
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Summary
MD5 is not a FIPS-approved algorithm, and some FIPS-enforced Python images remove
hashlib.md5entirely. BecauseDigestAuthreferenceshashlib.md5in a class-level dictionary, this causes anAttributeErrorat import time, making the entirehttpx2library unusable on these environments, even if MD5 digest auth is never used.This change conditionally registers the MD5 algorithm entries only when
hashlib.md5is present, so httpx2 can be imported on FIPS-enforced environments while preserving full MD5 digest auth support elsewhere. When a server requests an unavailable algorithm, a clearProtocolErroris raised instead of an opaqueKeyError.Discussion: #1094
Checklist