Skip to content
Myr

requests/auth: Handle an empty 'qop' attribute in a Authenticate challenge

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Some malfunctioning HTTP servers may return a qop directive with no token, as opposed to correctly omitting the qop directive completely. For example: header: WWW-Authenticate: Digest realm="foobar_api_auth", qop="", nonce="a12059eaaad0b86ece8f62f04cbafed6", algorithm="MD5", stale="false" Prior to this patch, requests would respond with a 'None' Authorization header. While the server is certainly incorrect, this patch updates requests to be more tolerant to this kind of shenaniganry. If we receive an empty string for the value of the qop attribute, we instead treat that as if the qop attribute was simply not provided. Closes #2916

authored by Matt Jordan · committed by Matt Jordan · parent 40ce366 · Browse files · 1 file+1 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:requests/auth.py+1 added-1 removed
134 unmodified lines
135 cnonce = (hashlib.sha1(s).hexdigest()[:16])136 if _algorithm == 'MD5-SESS':137 HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce))138139 if qop is None:139 if not qop:140 respdig = KD(HA1, "%s:%s" % (nonce, HA2))141 elif qop == 'auth' or 'auth' in qop.split(','):142 noncebit = "%s:%s:%s:%s:%s" % (143 nonce, ncvalue, cnonce, 'auth', HA2
80 unmodified lines