diff options
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-26137.patch')
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-26137.patch | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-26137.patch b/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-26137.patch new file mode 100644 index 0000000000..3cc8bcd02a --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-26137.patch | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | From 1dd69c5c5982fae7c87a620d487c2ebf7a6b436b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Seth Michael Larson <sethmichaellarson@gmail.com> | ||
| 3 | Date: Mon, 17 Feb 2020 15:34:48 -0600 | ||
| 4 | Subject: [PATCH] Raise ValueError if method contains control characters | ||
| 5 | (#1800) | ||
| 6 | |||
| 7 | CVE: CVE-2020-26137 | ||
| 8 | Upstream-Status: Backport [https://github.com/urllib3/urllib3/commit/1dd69c5c5982fae7c87a620d487c2ebf7a6b436b.patch] | ||
| 9 | Signed-off-by: Nikhil R <nikhil.r@kpit.com> | ||
| 10 | Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com> | ||
| 11 | Comment: Removed one hunk in CHANGES.rst and refresh other to remove | ||
| 12 | patch fuzz warnings | ||
| 13 | |||
| 14 | --- | ||
| 15 | src/urllib3/connection.py | 14 ++++++++++++++ | ||
| 16 | test/with_dummyserver/test_connectionpool.py | 6 ++++++ | ||
| 17 | 2 files changed, 20 insertions(+) | ||
| 18 | |||
| 19 | diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py | ||
| 20 | index 71e6790b1b..f7b1760938 100644 | ||
| 21 | --- a/src/urllib3/connection.py | ||
| 22 | +++ b/src/urllib3/connection.py | ||
| 23 | @@ -1,4 +1,5 @@ | ||
| 24 | from __future__ import absolute_import | ||
| 25 | +import re | ||
| 26 | import datetime | ||
| 27 | import logging | ||
| 28 | import os | ||
| 29 | @@ -58,6 +59,8 @@ port_by_scheme = {"http": 80, "https": 443} | ||
| 30 | # (ie test_recent_date is failing) update it to ~6 months before the current date. | ||
| 31 | RECENT_DATE = datetime.date(2019, 1, 1) | ||
| 32 | |||
| 33 | +_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]") | ||
| 34 | + | ||
| 35 | |||
| 36 | class DummyConnection(object): | ||
| 37 | """Used to detect a failed ConnectionCls import.""" | ||
| 38 | @@ -184,6 +187,17 @@ class HTTPConnection(_HTTPConnection, object): | ||
| 39 | conn = self._new_conn() | ||
| 40 | self._prepare_conn(conn) | ||
| 41 | |||
| 42 | + def putrequest(self, method, url, *args, **kwargs): | ||
| 43 | + """Send a request to the server""" | ||
| 44 | + match = _CONTAINS_CONTROL_CHAR_RE.search(method) | ||
| 45 | + if match: | ||
| 46 | + raise ValueError( | ||
| 47 | + "Method cannot contain non-token characters %r (found at least %r)" | ||
| 48 | + % (method, match.group()) | ||
| 49 | + ) | ||
| 50 | + | ||
| 51 | + return _HTTPConnection.putrequest(self, method, url, *args, **kwargs) | ||
| 52 | + | ||
| 53 | def request_chunked(self, method, url, body=None, headers=None): | ||
| 54 | """ | ||
| 55 | Alternative to the common request method, which sends the | ||
| 56 | diff --git a/test/with_dummyserver/test_connectionpool.py b/test/with_dummyserver/test_connectionpool.py | ||
| 57 | index 57f0dbd2f4..79cbd27185 100644 | ||
| 58 | --- a/test/with_dummyserver/test_connectionpool.py | ||
| 59 | +++ b/test/with_dummyserver/test_connectionpool.py | ||
| 60 | @@ -677,6 +677,12 @@ class TestConnectionPool(HTTPDummyServerTestCase): | ||
| 61 | with pytest.raises(MaxRetryError): | ||
| 62 | pool.request("GET", "/test", retries=2) | ||
| 63 | |||
| 64 | + @pytest.mark.parametrize("char", [" ", "\r", "\n", "\x00"]) | ||
| 65 | + def test_invalid_method_not_allowed(self, char): | ||
| 66 | + with pytest.raises(ValueError): | ||
| 67 | + with HTTPConnectionPool(self.host, self.port) as pool: | ||
| 68 | + pool.request("GET" + char, "/") | ||
| 69 | + | ||
| 70 | def test_percent_encode_invalid_target_chars(self): | ||
| 71 | with HTTPConnectionPool(self.host, self.port) as pool: | ||
| 72 | r = pool.request("GET", "/echo_params?q=\r&k=\n \n") | ||
