summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnuj Mittal <anuj.mittal@intel.com>2019-07-30 20:26:53 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-10-08 22:52:27 +0100
commit20ee17a579f89c2cdf39496b5bfd20d815414a3c (patch)
tree7690fbd0fd9de401190eb2f7ea5644a66691ac2b
parentd581f111dbeb891a25683dacf1a4a939fa5ef603 (diff)
downloadpoky-20ee17a579f89c2cdf39496b5bfd20d815414a3c.tar.gz
python3: fix CVE-2019-9740
CVE-2019-9947 is same as CVE-2019-9740 and mark it as such. See: https://bugs.python.org/issue30458 (From OE-Core rev: ad90312adabbad951f62e3bd4ad95fcc763ad0c4) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-devtools/python/python3/CVE-2019-9740.patch155
-rw-r--r--meta/recipes-devtools/python/python3_3.5.6.bb1
2 files changed, 156 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python3/CVE-2019-9740.patch b/meta/recipes-devtools/python/python3/CVE-2019-9740.patch
new file mode 100644
index 0000000000..8370901696
--- /dev/null
+++ b/meta/recipes-devtools/python/python3/CVE-2019-9740.patch
@@ -0,0 +1,155 @@
1From afe3a4975cf93c97e5d6eb8800e48f368011d37a Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
3Date: Sun, 14 Jul 2019 11:07:11 +0200
4Subject: [PATCH] bpo-30458: Disallow control chars in http URLs. (GH-12755)
5 (#13207)
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10Disallow control chars in http URLs in urllib.urlopen. This addresses a potential security problem for applications that do not sanity check their URLs where http request headers could be injected.
11
12Disable https related urllib tests on a build without ssl (GH-13032)
13These tests require an SSL enabled build. Skip these tests when python is built without SSL to fix test failures.
14
15Use http.client.InvalidURL instead of ValueError as the new error case's exception. (GH-13044)
16
17Co-Authored-By: Miro HronĨok <miro@hroncok.cz>
18Upstream-Status: Backport[https://github.com/python/cpython/commit/afe3a4975cf93c97e5d6eb8800e48f368011d37a]
19CVE: CVE-2019-9740
20CVE: CVE-2019-9947
21Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
22---
23 Lib/http/client.py | 16 ++++++
24 Lib/test/test_urllib.py | 55 +++++++++++++++++++
25 Lib/test/test_xmlrpc.py | 8 ++-
26 .../2019-04-10-08-53-30.bpo-30458.51E-DA.rst | 1 +
27 4 files changed, 79 insertions(+), 1 deletion(-)
28 create mode 100644 Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst
29
30diff --git a/Lib/http/client.py b/Lib/http/client.py
31index 352c1017adce..76b9be69a374 100644
32--- a/Lib/http/client.py
33+++ b/Lib/http/client.py
34@@ -141,6 +141,16 @@
35 _is_legal_header_name = re.compile(rb'[^:\s][^:\r\n]*').fullmatch
36 _is_illegal_header_value = re.compile(rb'\n(?![ \t])|\r(?![ \t\n])').search
37
38+# These characters are not allowed within HTTP URL paths.
39+# See https://tools.ietf.org/html/rfc3986#section-3.3 and the
40+# https://tools.ietf.org/html/rfc3986#appendix-A pchar definition.
41+# Prevents CVE-2019-9740. Includes control characters such as \r\n.
42+# We don't restrict chars above \x7f as putrequest() limits us to ASCII.
43+_contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f]')
44+# Arguably only these _should_ allowed:
45+# _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$")
46+# We are more lenient for assumed real world compatibility purposes.
47+
48 # We always set the Content-Length header for these methods because some
49 # servers will otherwise respond with a 411
50 _METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}
51@@ -978,6 +988,12 @@ def putrequest(self, method, url, skip_host=False,
52 self._method = method
53 if not url:
54 url = '/'
55+ # Prevent CVE-2019-9740.
56+ match = _contains_disallowed_url_pchar_re.search(url)
57+ if match:
58+ raise InvalidURL("URL can't contain control characters. {!r} "
59+ "(found at least {!r})".format(url,
60+ match.group()))
61 request = '%s %s %s' % (method, url, self._http_vsn_str)
62
63 # Non-ASCII characters should have been eliminated earlier
64diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
65index 3afb1312de32..1e2c622e29fd 100644
66--- a/Lib/test/test_urllib.py
67+++ b/Lib/test/test_urllib.py
68@@ -330,6 +330,61 @@ def test_willclose(self):
69 finally:
70 self.unfakehttp()
71
72+ @unittest.skipUnless(ssl, "ssl module required")
73+ def test_url_with_control_char_rejected(self):
74+ for char_no in list(range(0, 0x21)) + [0x7f]:
75+ char = chr(char_no)
76+ schemeless_url = "//localhost:7777/test{}/".format(char)
77+ self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
78+ try:
79+ # We explicitly test urllib.request.urlopen() instead of the top
80+ # level 'def urlopen()' function defined in this... (quite ugly)
81+ # test suite. They use different url opening codepaths. Plain
82+ # urlopen uses FancyURLOpener which goes via a codepath that
83+ # calls urllib.parse.quote() on the URL which makes all of the
84+ # above attempts at injection within the url _path_ safe.
85+ escaped_char_repr = repr(char).replace('\\', r'\\')
86+ InvalidURL = http.client.InvalidURL
87+ with self.assertRaisesRegex(
88+ InvalidURL,
89+ "contain control.*{}".format(escaped_char_repr)):
90+ urllib.request.urlopen("http:{}".format(schemeless_url))
91+ with self.assertRaisesRegex(
92+ InvalidURL,
93+ "contain control.*{}".format(escaped_char_repr)):
94+ urllib.request.urlopen("https:{}".format(schemeless_url))
95+ # This code path quotes the URL so there is no injection.
96+ resp = urlopen("http:{}".format(schemeless_url))
97+ self.assertNotIn(char, resp.geturl())
98+ finally:
99+ self.unfakehttp()
100+
101+ @unittest.skipUnless(ssl, "ssl module required")
102+ def test_url_with_newline_header_injection_rejected(self):
103+ self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
104+ host = "localhost:7777?a=1 HTTP/1.1\r\nX-injected: header\r\nTEST: 123"
105+ schemeless_url = "//" + host + ":8080/test/?test=a"
106+ try:
107+ # We explicitly test urllib.request.urlopen() instead of the top
108+ # level 'def urlopen()' function defined in this... (quite ugly)
109+ # test suite. They use different url opening codepaths. Plain
110+ # urlopen uses FancyURLOpener which goes via a codepath that
111+ # calls urllib.parse.quote() on the URL which makes all of the
112+ # above attempts at injection within the url _path_ safe.
113+ InvalidURL = http.client.InvalidURL
114+ with self.assertRaisesRegex(
115+ InvalidURL, r"contain control.*\\r.*(found at least . .)"):
116+ urllib.request.urlopen("http:{}".format(schemeless_url))
117+ with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"):
118+ urllib.request.urlopen("https:{}".format(schemeless_url))
119+ # This code path quotes the URL so there is no injection.
120+ resp = urlopen("http:{}".format(schemeless_url))
121+ self.assertNotIn(' ', resp.geturl())
122+ self.assertNotIn('\r', resp.geturl())
123+ self.assertNotIn('\n', resp.geturl())
124+ finally:
125+ self.unfakehttp()
126+
127 def test_read_0_9(self):
128 # "0.9" response accepted (but not "simple responses" without
129 # a status line)
130diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
131index c2de057ecbfa..99e510fcee86 100644
132--- a/Lib/test/test_xmlrpc.py
133+++ b/Lib/test/test_xmlrpc.py
134@@ -896,7 +896,13 @@ def test_unicode_host(self):
135 def test_partial_post(self):
136 # Check that a partial POST doesn't make the server loop: issue #14001.
137 conn = http.client.HTTPConnection(ADDR, PORT)
138- conn.request('POST', '/RPC2 HTTP/1.0\r\nContent-Length: 100\r\n\r\nbye')
139+ conn.send('POST /RPC2 HTTP/1.0\r\n'
140+ 'Content-Length: 100\r\n\r\n'
141+ 'bye HTTP/1.1\r\n'
142+ 'Host: {}:{}\r\n'
143+ 'Accept-Encoding: identity\r\n'
144+ 'Content-Length: 0\r\n\r\n'
145+ .format(ADDR, PORT).encode('ascii'))
146 conn.close()
147
148 def test_context_manager(self):
149diff --git a/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst b/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst
150new file mode 100644
151index 000000000000..ed8027fb4d64
152--- /dev/null
153+++ b/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst
154@@ -0,0 +1 @@
155+Address CVE-2019-9740 by disallowing URL paths with embedded whitespace or control characters through into the underlying http client request. Such potentially malicious header injection URLs now cause an http.client.InvalidURL exception to be raised.
diff --git a/meta/recipes-devtools/python/python3_3.5.6.bb b/meta/recipes-devtools/python/python3_3.5.6.bb
index 6aa6df658c..7e74c55b80 100644
--- a/meta/recipes-devtools/python/python3_3.5.6.bb
+++ b/meta/recipes-devtools/python/python3_3.5.6.bb
@@ -43,6 +43,7 @@ SRC_URI += "\
43 file://0004-bpo-33570-TLS-1.3-ciphers-for-OpenSSL-1.1.1-GH-6976.patch \ 43 file://0004-bpo-33570-TLS-1.3-ciphers-for-OpenSSL-1.1.1-GH-6976.patch \
44 file://0005-bpo-30714-ALPN-changes-for-OpenSSL-1.1.0f-2305.patch \ 44 file://0005-bpo-30714-ALPN-changes-for-OpenSSL-1.1.0f-2305.patch \
45 file://run-ptest \ 45 file://run-ptest \
46 file://CVE-2019-9740.patch \
46 " 47 "
47 48
48inherit multilib_header python3native update-alternatives qemu ptest 49inherit multilib_header python3native update-alternatives qemu ptest