88b68c0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
88b68c0
From: Fedora Python maintainers <python-devel@lists.fedoraproject.org>
88b68c0
Date: Wed, 22 Jul 2020 16:38:43 +0200
88b68c0
Subject: [PATCH] 00320-CVE-2019-10160.patch
88b68c0
88b68c0
Security fix for CVE-2019-10160: Information Disclosure due to urlsplit improper NFKC normalization
88b68c0
Fixed upstream for later branches: https://bugs.python.org/issue36742
88b68c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1718867
88b68c0
---
88b68c0
 Lib/test/test_urlparse.py |  6 ++++++
88b68c0
 Lib/urllib/parse.py       | 11 +++++++----
88b68c0
 2 files changed, 13 insertions(+), 4 deletions(-)
88b68c0
97a118a
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
88b68c0
index 77c200729a2..c6c54b03c30 100644
97a118a
--- a/Lib/test/test_urlparse.py
97a118a
+++ b/Lib/test/test_urlparse.py
97a118a
@@ -885,6 +885,12 @@ class UrlParseTestCase(unittest.TestCase):
97a118a
         self.assertIn('\u2100', denorm_chars)
97a118a
         self.assertIn('\uFF03', denorm_chars)
97a118a
 
97a118a
+        # bpo-36742: Verify port separators are ignored when they
97a118a
+        # existed prior to decomposition
97a118a
+        urllib.parse.urlsplit('http://\u30d5\u309a:80')
97a118a
+        with self.assertRaises(ValueError):
97a118a
+            urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')
97a118a
+
97a118a
         for scheme in ["http", "https", "ftp"]:
97a118a
             for c in denorm_chars:
97a118a
                 url = "{}://netloc{}false.netloc/path".format(scheme, c)
97a118a
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
88b68c0
index 243f470a289..da3a40c395c 100644
97a118a
--- a/Lib/urllib/parse.py
97a118a
+++ b/Lib/urllib/parse.py
97a118a
@@ -322,13 +322,16 @@ def _checknetloc(netloc):
97a118a
     # looking for characters like \u2100 that expand to 'a/c'
97a118a
     # IDNA uses NFKC equivalence, so normalize for this check
97a118a
     import unicodedata
97a118a
-    netloc2 = unicodedata.normalize('NFKC', netloc)
97a118a
-    if netloc == netloc2:
97a118a
+    n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
97a118a
+    n = n.replace(':', '')        # ignore characters already included
97a118a
+    n = n.replace('#', '')        # but not the surrounding text
97a118a
+    n = n.replace('?', '')
97a118a
+    netloc2 = unicodedata.normalize('NFKC', n)
97a118a
+    if n == netloc2:
97a118a
         return
97a118a
-    _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay
97a118a
     for c in '/?#@:':
97a118a
         if c in netloc2:
97a118a
-            raise ValueError("netloc '" + netloc2 + "' contains invalid " +
97a118a
+            raise ValueError("netloc '" + netloc + "' contains invalid " +
97a118a
                              "characters under NFKC normalization")
97a118a
 
97a118a
 def urlsplit(url, scheme='', allow_fragments=True):