Skip to content

Commit e4686b7

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 45c4112 commit e4686b7

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