Skip to content

Commit 51d5dba

Browse files
authored
Fix digest auth dropping challenge fields with empty string values (aio-libs#12097)
1 parent dab9e87 commit 51d5dba

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGES/12097.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed digest auth dropping challenge fields with empty string values -- by :user:`bysiber`.

aiohttp/client_middleware_digest_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def _authenticate(self, response: ClientResponse) -> bool:
414414
# Extract challenge parameters
415415
self._challenge = {}
416416
for field in CHALLENGE_FIELDS:
417-
if value := header_pairs.get(field):
417+
if (value := header_pairs.get(field)) is not None:
418418
self._challenge[field] = value
419419

420420
# Update protection space based on domain parameter or default to origin

tests/test_client_middleware_digest_auth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def mock_md5_digest() -> Generator[mock.MagicMock, None, None]:
114114
True,
115115
{"realm": "test", "nonce": "abc", "qop": "auth"},
116116
),
117+
# Valid digest with empty realm (RFC 7616 Section 3.3 allows this)
118+
(
119+
401,
120+
{"www-authenticate": 'Digest realm="", nonce="abc", qop="auth"'},
121+
True,
122+
{"realm": "", "nonce": "abc", "qop": "auth"},
123+
),
117124
# Non-401 status
118125
(200, {}, False, {}), # No challenge should be set
119126
],

0 commit comments

Comments
 (0)