Skip to content

Commit 5e260e0

Browse files
bpo-39548: Fix handling of 'WWW-Authenticate' header for Digest Auth (GH-18338)
* bpo-39548: Fix handling of 'WWW-Authenticate' header for Digest authentication - The 'qop' value in the 'WWW-Authenticate' header is optional. The presence of 'qop' in the header should be checked before its value is parsed with 'split'. Signed-off-by: Stephen Balousek <[email protected]> * bpo-39548: Fix handling of 'WWW-Authenticate' header for Digest authentication - Add NEWS item Signed-off-by: Stephen Balousek <[email protected]> * Update Misc/NEWS.d/next/Library/2020-02-06-05-33-52.bpo-39548.DF4FFe.rst Co-Authored-By: Brandt Bucher <[email protected]> Co-authored-by: Brandt Bucher <[email protected]>
1 parent eb47fd5 commit 5e260e0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/urllib/request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,9 @@ def get_authorization(self, req, chal):
11381138
req.selector)
11391139
# NOTE: As per RFC 2617, when server sends "auth,auth-int", the client could use either `auth`
11401140
# or `auth-int` to the response back. we use `auth` to send the response back.
1141-
if 'auth' in qop.split(','):
1141+
if qop is None:
1142+
respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
1143+
elif 'auth' in qop.split(','):
11421144
if nonce == self.last_nonce:
11431145
self.nonce_count += 1
11441146
else:
@@ -1148,8 +1150,6 @@ def get_authorization(self, req, chal):
11481150
cnonce = self.get_cnonce(nonce)
11491151
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, 'auth', H(A2))
11501152
respdig = KD(H(A1), noncebit)
1151-
elif qop is None:
1152-
respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
11531153
else:
11541154
# XXX handle auth-int.
11551155
raise URLError("qop '%s' is not supported." % qop)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix handling of header in :class:`urllib.request.AbstractDigestAuthHandler` when the optional ``qop`` parameter
2+
is not present.

0 commit comments

Comments
 (0)