[New-bugs-announce] [issue39503] [security] Denial of service in urllib.request.AbstractBasicAuthHandler
report at bugs.python.org
Thu Jan 30 10:11:29 EST 2020
New submission from STINNER Victor <vstinner at python.org>:
Copy of an email received on the Python Security Response team, 9 days ago. I consider that it's not worth it to have an embargo on this vulnerability, so I make it public.
I believe I've found a denial-of-service (DoS) bug in
urllib.request.AbstractBasicAuthHandler. To start, I'm operating on some
background information from this document: HTTP authentication
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication>. The bug
itself is a ReDoS <https://www.regular-expressions.info/redos.html> bug
causing catastrophic backtracking. To reproduce the issue we can use the
from urllib.request import AbstractBasicAuthHandler
auth_handler = AbstractBasicAuthHandler()
'www-authenticate': 'Basic ' + ',' * 64 + ' ' + 'foo' + ' ' +
The issue itself is in the following regular expression:
rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
In particular, the (?:.*,)* portion. Since "." and "," overlap and there
are nested quantifiers we can cause catastrophic backtracking by repeating
a comma. Note that since AbstractBasicAuthHandler is vulnerable, then both
HTTPBasicAuthHandler and ProxyBasicAuthHandler are as well because they
call http_error_auth_reqed. Building from the HTTP authentication document
above, this means a server can send a specially crafted header along with
an HTTP 401 or HTTP 407 and cause a DoS on the client.
I won't speculate on the severity of the issue too much - you will surely
understand the impact better than I will. Although, the fact that this is
client-side as opposed to server-side appears to reduce the severity,
however the fact that it's a security-sensitive context (HTTP
authentication) may raise the severity.
One possible fix would be changing the rx expression to the following:
rx = re.compile('(?:[^,]*,)*[ \t]*([^ \t]+)[ \t]+'
This removes the character overlap in the nested quantifier and thus
negates the catastrophic backtracking.
Let me know if you have any questions or what the next steps are from here.
Thanks for supporting Python security!
components: Library (Lib)
title: [security] Denial of service in urllib.request.AbstractBasicAuthHandler
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce