Blame SOURCES/CVE-2021-33503.patch

53b174
From d5e3238b87fc557600618f18179e821a4a1c7577 Mon Sep 17 00:00:00 2001
53b174
From: Lumir Balhar <lbalhar@redhat.com>
53b174
Date: Tue, 29 Jun 2021 16:03:37 +0200
53b174
Subject: [PATCH] CVE-2021-33503
53b174
53b174
---
53b174
 src/urllib3/util/url.py |  8 +++++---
53b174
 test/test_util.py       | 10 ++++++++++
53b174
 2 files changed, 15 insertions(+), 3 deletions(-)
53b174
53b174
diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py
53b174
index 8ef5a23..7fb2650 100644
53b174
--- a/src/urllib3/util/url.py
53b174
+++ b/src/urllib3/util/url.py
53b174
@@ -63,12 +63,12 @@ IPV6_ADDRZ_RE = re.compile("^" + IPV6_ADDRZ_PAT + "$")
53b174
 BRACELESS_IPV6_ADDRZ_RE = re.compile("^" + IPV6_ADDRZ_PAT[2:-2] + "$")
53b174
 ZONE_ID_RE = re.compile("(" + ZONE_ID_PAT + r")\]$")
53b174
 
53b174
-SUBAUTHORITY_PAT = (u"^(?:(.*)@)?(%s|%s|%s)(?::([0-9]{0,5}))?$") % (
53b174
+_HOST_PORT_PAT = ("^(%s|%s|%s)(?::([0-9]{0,5}))?$") % (
53b174
     REG_NAME_PAT,
53b174
     IPV4_PAT,
53b174
     IPV6_ADDRZ_PAT,
53b174
 )
53b174
-SUBAUTHORITY_RE = re.compile(SUBAUTHORITY_PAT, re.UNICODE | re.DOTALL)
53b174
+_HOST_PORT_RE = re.compile(_HOST_PORT_PAT, re.UNICODE | re.DOTALL)
53b174
 
53b174
 UNRESERVED_CHARS = set(
53b174
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-~"
53b174
@@ -365,7 +365,9 @@ def parse_url(url):
53b174
             scheme = scheme.lower()
53b174
 
53b174
         if authority:
53b174
-            auth, host, port = SUBAUTHORITY_RE.match(authority).groups()
53b174
+            auth, _, host_port = authority.rpartition("@")
53b174
+            auth = auth or None
53b174
+            host, port = _HOST_PORT_RE.match(host_port).groups()
53b174
             if auth and normalize_uri:
53b174
                 auth = _encode_invalid_chars(auth, USERINFO_CHARS)
53b174
             if port == "":
53b174
diff --git a/test/test_util.py b/test/test_util.py
53b174
index 42c3882..04c90b0 100644
53b174
--- a/test/test_util.py
53b174
+++ b/test/test_util.py
53b174
@@ -425,6 +425,16 @@ class TestUtil(object):
53b174
                 query="%0D%0ASET%20test%20failure12%0D%0A:8080/test/?test=a",
53b174
             ),
53b174
         ),
53b174
+        # Tons of '@' causing backtracking
53b174
+        ("https://" + ("@" * 10000) + "[", False),
53b174
+        (
53b174
+            "https://user:" + ("@" * 10000) + "example.com",
53b174
+            Url(
53b174
+                scheme="https",
53b174
+                auth="user:" + ("%40" * 9999),
53b174
+                host="example.com",
53b174
+            ),
53b174
+        ),
53b174
     ]
53b174
 
53b174
     @pytest.mark.parametrize("url, expected_url", url_vulnerabilities)
53b174
-- 
53b174
2.31.1
53b174