DigestAuth class definition crashes on FIPS-enforced Python (hashlib.md5 unavailable) #1094
Unanswered
mwatkins-ld
asked this question in
Q&A
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
On FIPS-enforced Python images, hashlib.md5 is not registered as a module attribute. This prevents httpx2 from being imported because DigestAuth references hashlib.md5 as a class-level attribute:
https://github.com/pydantic/httpx2/blob/main/src/httpx2/httpx2/_auth.py#L171-L172
Since this is evaluated at class definition time, it crashes when the module is imported, regardless of whether DigestAuth is ever used.
Reproduction
On a FIPS-enforced Python image:
Suggested fix
Conditionally register MD5 so the class defines without error on FIPS systems:
This preserves full MD5 Digest Auth support on non-FIPS systems while allowing httpx2 to be imported on FIPS-enforced environments. Users who attempt MD5 Digest Auth on a FIPS system would get a clear KeyError at runtime rather than the entire library being unimportable.
Even though Python 3.9 added support to hashlib
usedForSecuritykwargFalse indicates that the hashing algorithm is not used in a security context, e.g. as a non-cryptographic one-way compression function.this does not feel like the correct fix since this is used in a security context for authentication and not strictly for checksums, cache keys, or some other non-security related functionality.Current Workaround
We currently use a sitecustomize.py that stubs hashlib.md5 with a function that raises ValueError if called:
This prevents the import crash but is a workaround we'd prefer not to do this because it requires explanations on why it appears like an unapproved algorithm is being stubbed.
All reactions