Fix HTTPDigestAuth URI field to include semicolons in URL paths #7069
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
This PR fixes a bug in
HTTPDigestAuthwhere semicolons in URL paths were being truncated from the digest authenticationurifield, causing authentication failures for APIs that use semicolons as path delimiters.Problem
When making authenticated requests to URLs containing semicolons in the path (e.g., MusicBrainz API:
/api/collection/id1/releases/uuid1;uuid2;uuid3), the HTTP Digest Authentication implementation was not including the URL parameters (semicolon-separated values) in theurifield of the Authorization header. According to RFC 2616, the URI should include the full request-uri, including any parameters.This caused authentication failures because the server-side digest calculation included the full path with semicolons, while the client-side calculation used a truncated path without them.
Solution
Modified
src/requests/auth.pyin theHTTPDigestAuth.build_digest_header()method to properly extract and include URL parameters (semicolons) when constructing the request-uri:The fix uses
urlparse().paramsto correctly handle semicolon-separated parameters and includes them in the path before appending any query string.Testing
Added comprehensive test coverage in
tests/test_requests.pywith three scenarios:/path/id1;id2;id3?param=valueare handled correctly/path/id1;id2;id3work without query stringsImpact
urifield of digest authentication incorrectly filled when the URL contains semicolons in path #6990Files Changed
src/requests/auth.py- 2 lines addedtests/test_requests.py- 39 lines added