Skip to content

Support FIPS-enforced Python builds without hashlib.md5 in DigestAuth - #1130

Merged
Kludex merged 12 commits into
pydantic:mainfrom
mwatkins-ld:fix/digest-auth-fips-compat
Oct 12, 2026
Merged

Kludex merged 12 commits into
pydantic:mainfrom
mwatkins-ld:fix/digest-auth-fips-compat

Conversation

@mwatkins-ld

@mwatkins-ld mwatkins-ld commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MD5 is not a FIPS-approved algorithm, and some FIPS-enforced Python images remove hashlib.md5 entirely. Because DigestAuth references hashlib.md5 in a class-level dictionary, this causes an AttributeError at import time, making the entire httpx2 library unusable on these environments, even if MD5 digest auth is never used.

This change conditionally registers the MD5 algorithm entries only when hashlib.md5 is 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 clear ProtocolError is raised instead of an opaque KeyError.

Discussion: #1094

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • (No documentation to update?)

Review in cubic

@codspeed

codspeed Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing mwatkins-ld:fix/digest-auth-fips-compat (8c7b029) with main (0286b40)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/httpx2/httpx2/_auth.py Resolved
Comment thread src/httpx2/httpx2/_auth.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/httpx2/test_auth.py Resolved

@mbeijen mbeijen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! @Kludex I think this is a nice fix

@mwatkins-ld

Copy link
Copy Markdown
Contributor Author

Thanks, looks good! @Kludex I think this is a nice fix

Any traction on this? Is there more to do?

@Kludex

Kludex commented Aug 27, 2026

Copy link
Copy Markdown
Member

It's on my radar. Sorry the delay, I'll get to this soon.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Re-trigger cubic

Comment thread tests/httpx2/test_auth.py Resolved
Comment thread src/httpx2/httpx2/_auth.py Resolved
@veria-ai

veria-ai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@Kludex Kludex changed the title fix: handle missing hashlib.md5 on FIPS-enforced Python Support FIPS-enforced Python builds without hashlib.md5 in DigestAuth Oct 12, 2026
@Kludex
Kludex merged commit d989385 into pydantic:main Oct 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants