Skip to content

Commit cf347f3

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]> (cherry picked from commit 5e260e0) Co-authored-by: Stephen Balousek <[email protected]>
1 parent 5157506 commit cf347f3

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
@@ -1145,7 +1145,9 @@ def get_authorization(self, req, chal):
11451145
req.selector)
11461146
# NOTE: As per RFC 2617, when server sends "auth,auth-int", the client could use either `auth`
11471147
# or `auth-int` to the response back. we use `auth` to send the response back.
1148-
if 'auth' in qop.split(','):
1148+
if qop is None:
1149+
respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
1150+
elif 'auth' in qop.split(','):
11491151
if nonce == self.last_nonce:
11501152
self.nonce_count += 1
11511153
else:
@@ -1155,8 +1157,6 @@ def get_authorization(self, req, chal):
11551157
cnonce = self.get_cnonce(nonce)
11561158
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, 'auth', H(A2))
11571159
respdig = KD(H(A1), noncebit)
1158-
elif qop is None:
1159-
respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
11601160
else:
11611161
# XXX handle auth-int.
11621162
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)