Repository navigation
Scope cached DigestAuth challenge to the origin that issued it - #3865
Open
Ramya-9353 wants to merge 1 commit into
Open
Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DigestAuthstores the server'sWWW-Authenticatechallenge inself._last_challengeand then pre-emptively attaches anAuthorizationheader to every later request made through the same auth instance, without checking which origin issued that challenge. Sincehttpx.Client(auth=httpx.DigestAuth(...))is the documented usage, one 401 from a single host makes the client authenticate against every host it talks to afterwards.Repro:
Observed on master:
evil.examplereceives the username and realm in cleartext plus a digest response computed over the password, which leaves the password open to an offline attack. Expected behaviour is that the second request carries noAuthorizationheader and negotiates separately against whichever origin actually challenges it, which is what happens after this change.NetRCAuthalready keys its credentials offrequest.url.host, so scoping the cached challenge the same way keeps the two schemes consistent. Reuse against the same origin is untouched andtest_digest_auth_reuses_challengestill passes.Verified locally on Python 3.12:
ruff format --diff,ruff checkandmypyclean,tests/test_auth.pyandtests/client/test_auth.pypass (89 passed, 1 skipped) withhttpx/_auth.pyat 100% coverage. The new test fails on master and passes with the fix. The modules that need the live uvicorn fixture could not bind a socket in my sandbox, and they behave the same way on an unpatched checkout.Checklist