Skip to content

Commit d0065ee

Browse files
author
Stephen Reichling
authored
Merge pull request #2 from ActiveState/shaunl/cve-2020-8492
Fix CVE-2020-8492 runaway regexp
2 parents e5c690f + 33e2642 commit d0065ee

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Lib/urllib2.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,16 @@ class AbstractBasicAuthHandler:
856856

857857
# allow for double- and single-quoted realm values
858858
# (single quotes are a violation of the RFC, but appear in the wild)
859-
rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
860-
'realm=(["\']?)([^"\']*)\\2', re.I)
859+
860+
rx = re.compile('(?:^|,)' # start of the string or ','
861+
'[ \t]*' # optional whitespaces
862+
'([^ \t]+)' # scheme like "Basic"
863+
'[ \t]+' # mandatory whitespaces
864+
# realm=xxx
865+
# realm='xxx'
866+
# realm="xxx"
867+
'realm=(["\']?)([^"\']*)\\2',
868+
re.I)
861869

862870
# XXX could pre-emptively send auth info already accepted (RFC 2617,
863871
# end of section 2, and section 1.2 immediately after "credentials"

0 commit comments

Comments
 (0)