summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python3/CVE-2019-9636.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/python/python3/CVE-2019-9636.patch')
-rw-r--r--meta/recipes-devtools/python/python3/CVE-2019-9636.patch154
1 files changed, 0 insertions, 154 deletions
diff --git a/meta/recipes-devtools/python/python3/CVE-2019-9636.patch b/meta/recipes-devtools/python/python3/CVE-2019-9636.patch
deleted file mode 100644
index 72128f0b0d..0000000000
--- a/meta/recipes-devtools/python/python3/CVE-2019-9636.patch
+++ /dev/null
@@ -1,154 +0,0 @@
1From daad2c482c91de32d8305abbccc76a5de8b3a8be Mon Sep 17 00:00:00 2001
2From: Steve Dower <steve.dower@microsoft.com>
3Date: Thu, 7 Mar 2019 09:08:18 -0800
4Subject: [PATCH] bpo-36216: Add check for characters in netloc that normalize
5 to separators (GH-12201)
6
7Upstream-Status: Backport
8CVE: CVE-2019-9636
9Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
10
11---
12 Doc/library/urllib.parse.rst | 18 +++++++++++++++
13 Lib/test/test_urlparse.py | 23 +++++++++++++++++++
14 Lib/urllib/parse.py | 17 ++++++++++++++
15 .../2019-03-06-09-38-40.bpo-36216.6q1m4a.rst | 3 +++
16 4 files changed, 61 insertions(+)
17 create mode 100644 Misc/NEWS.d/next/Security/2019-03-06-09-38-40.bpo-36216.6q1m4a.rst
18
19diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst
20index 0c8f0f607314..b565e1edd321 100644
21--- a/Doc/library/urllib.parse.rst
22+++ b/Doc/library/urllib.parse.rst
23@@ -124,6 +124,11 @@ or on combining URL components into a URL string.
24 Unmatched square brackets in the :attr:`netloc` attribute will raise a
25 :exc:`ValueError`.
26
27+ Characters in the :attr:`netloc` attribute that decompose under NFKC
28+ normalization (as used by the IDNA encoding) into any of ``/``, ``?``,
29+ ``#``, ``@``, or ``:`` will raise a :exc:`ValueError`. If the URL is
30+ decomposed before parsing, no error will be raised.
31+
32 .. versionchanged:: 3.2
33 Added IPv6 URL parsing capabilities.
34
35@@ -136,6 +141,10 @@ or on combining URL components into a URL string.
36 Out-of-range port numbers now raise :exc:`ValueError`, instead of
37 returning :const:`None`.
38
39+ .. versionchanged:: 3.7.3
40+ Characters that affect netloc parsing under NFKC normalization will
41+ now raise :exc:`ValueError`.
42+
43
44 .. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None)
45
46@@ -257,10 +266,19 @@ or on combining URL components into a URL string.
47 Unmatched square brackets in the :attr:`netloc` attribute will raise a
48 :exc:`ValueError`.
49
50+ Characters in the :attr:`netloc` attribute that decompose under NFKC
51+ normalization (as used by the IDNA encoding) into any of ``/``, ``?``,
52+ ``#``, ``@``, or ``:`` will raise a :exc:`ValueError`. If the URL is
53+ decomposed before parsing, no error will be raised.
54+
55 .. versionchanged:: 3.6
56 Out-of-range port numbers now raise :exc:`ValueError`, instead of
57 returning :const:`None`.
58
59+ .. versionchanged:: 3.7.3
60+ Characters that affect netloc parsing under NFKC normalization will
61+ now raise :exc:`ValueError`.
62+
63
64 .. function:: urlunsplit(parts)
65
66diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
67index be50b47603aa..e6638aee2244 100644
68--- a/Lib/test/test_urlparse.py
69+++ b/Lib/test/test_urlparse.py
70@@ -1,3 +1,5 @@
71+import sys
72+import unicodedata
73 import unittest
74 import urllib.parse
75
76@@ -984,6 +986,27 @@ def test_all(self):
77 expected.append(name)
78 self.assertCountEqual(urllib.parse.__all__, expected)
79
80+ def test_urlsplit_normalization(self):
81+ # Certain characters should never occur in the netloc,
82+ # including under normalization.
83+ # Ensure that ALL of them are detected and cause an error
84+ illegal_chars = '/:#?@'
85+ hex_chars = {'{:04X}'.format(ord(c)) for c in illegal_chars}
86+ denorm_chars = [
87+ c for c in map(chr, range(128, sys.maxunicode))
88+ if (hex_chars & set(unicodedata.decomposition(c).split()))
89+ and c not in illegal_chars
90+ ]
91+ # Sanity check that we found at least one such character
92+ self.assertIn('\u2100', denorm_chars)
93+ self.assertIn('\uFF03', denorm_chars)
94+
95+ for scheme in ["http", "https", "ftp"]:
96+ for c in denorm_chars:
97+ url = "{}://netloc{}false.netloc/path".format(scheme, c)
98+ with self.subTest(url=url, char='{:04X}'.format(ord(c))):
99+ with self.assertRaises(ValueError):
100+ urllib.parse.urlsplit(url)
101
102 class Utility_Tests(unittest.TestCase):
103 """Testcase to test the various utility functions in the urllib."""
104diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
105index f691ab74f87f..39c5d6a80824 100644
106--- a/Lib/urllib/parse.py
107+++ b/Lib/urllib/parse.py
108@@ -391,6 +391,21 @@ def _splitnetloc(url, start=0):
109 delim = min(delim, wdelim) # use earliest delim position
110 return url[start:delim], url[delim:] # return (domain, rest)
111
112+def _checknetloc(netloc):
113+ if not netloc or netloc.isascii():
114+ return
115+ # looking for characters like \u2100 that expand to 'a/c'
116+ # IDNA uses NFKC equivalence, so normalize for this check
117+ import unicodedata
118+ netloc2 = unicodedata.normalize('NFKC', netloc)
119+ if netloc == netloc2:
120+ return
121+ _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay
122+ for c in '/?#@:':
123+ if c in netloc2:
124+ raise ValueError("netloc '" + netloc2 + "' contains invalid " +
125+ "characters under NFKC normalization")
126+
127 def urlsplit(url, scheme='', allow_fragments=True):
128 """Parse a URL into 5 components:
129 <scheme>://<netloc>/<path>?<query>#<fragment>
130@@ -419,6 +434,7 @@ def urlsplit(url, scheme='', allow_fragments=True):
131 url, fragment = url.split('#', 1)
132 if '?' in url:
133 url, query = url.split('?', 1)
134+ _checknetloc(netloc)
135 v = SplitResult('http', netloc, url, query, fragment)
136 _parse_cache[key] = v
137 return _coerce_result(v)
138@@ -442,6 +458,7 @@ def urlsplit(url, scheme='', allow_fragments=True):
139 url, fragment = url.split('#', 1)
140 if '?' in url:
141 url, query = url.split('?', 1)
142+ _checknetloc(netloc)
143 v = SplitResult(scheme, netloc, url, query, fragment)
144 _parse_cache[key] = v
145 return _coerce_result(v)
146diff --git a/Misc/NEWS.d/next/Security/2019-03-06-09-38-40.bpo-36216.6q1m4a.rst b/Misc/NEWS.d/next/Security/2019-03-06-09-38-40.bpo-36216.6q1m4a.rst
147new file mode 100644
148index 000000000000..5546394157f9
149--- /dev/null
150+++ b/Misc/NEWS.d/next/Security/2019-03-06-09-38-40.bpo-36216.6q1m4a.rst
151@@ -0,0 +1,3 @@
152+Changes urlsplit() to raise ValueError when the URL contains characters that
153+decompose under IDNA encoding (NFKC-normalization) into characters that
154+affect how the URL is parsed.