summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaiqing Bai <Haiqing.Bai@windriver.com>2020-03-13 18:19:23 +0800
committerArmin Kuster <akuster808@gmail.com>2020-03-21 19:46:18 -0700
commit6d38a12f165445a7b47f784d705ab6692c93a6b0 (patch)
treeb154d81dd7c959b2c4a74e106654fd65d7d5f207
parent9aea795890af4de0b8e6587f1f2778109446736d (diff)
downloadmeta-openembedded-6d38a12f165445a7b47f784d705ab6692c93a6b0.tar.gz
python-urllib3/python3-urllib3: fix CVE-2020-7212
Optimize _encode_invalid_chars for a denial of service (CPU consumption) Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r--meta-python/recipes-devtools/python/python-urllib3/CVE-2020-7212.patch54
-rw-r--r--meta-python/recipes-devtools/python/python-urllib3_1.25.6.bb2
-rw-r--r--meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-7212.patch54
-rw-r--r--meta-python/recipes-devtools/python/python3-urllib3_1.25.6.bb2
4 files changed, 112 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python-urllib3/CVE-2020-7212.patch b/meta-python/recipes-devtools/python/python-urllib3/CVE-2020-7212.patch
new file mode 100644
index 000000000..a2bb0fb5b
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python-urllib3/CVE-2020-7212.patch
@@ -0,0 +1,54 @@
1From aff951b7a41eb5b958b32c49eaa00da02adc9c2d Mon Sep 17 00:00:00 2001
2From: Quentin Pradet <quentin.pradet@gmail.com>
3Date: Tue, 21 Jan 2020 22:32:56 +0400
4Subject: [PATCH] Optimize _encode_invalid_chars (#1787)
5
6Co-authored-by: Seth Michael Larson <sethmichaellarson@gmail.com>
7
8Upstream-Status: Backport
9[from git://github.com/urllib3/urllib3.git commit:a2697e7c6b]
10Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>
11---
12 src/urllib3/util/url.py | 15 ++++++---------
13 1 file changed, 6 insertions(+), 9 deletions(-)
14
15diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py
16index 9675f74..e353937 100644
17--- a/src/urllib3/util/url.py
18+++ b/src/urllib3/util/url.py
19@@ -216,18 +216,15 @@ def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
20
21 component = six.ensure_text(component)
22
23+ # Normalize existing percent-encoded bytes.
24 # Try to see if the component we're encoding is already percent-encoded
25 # so we can skip all '%' characters but still encode all others.
26- percent_encodings = PERCENT_RE.findall(component)
27-
28- # Normalize existing percent-encoded bytes.
29- for enc in percent_encodings:
30- if not enc.isupper():
31- component = component.replace(enc, enc.upper())
32+ component, percent_encodings = PERCENT_RE.subn(
33+ lambda match: match.group(0).upper(), component
34+ )
35
36 uri_bytes = component.encode("utf-8", "surrogatepass")
37- is_percent_encoded = len(percent_encodings) == uri_bytes.count(b"%")
38-
39+ is_percent_encoded = percent_encodings == uri_bytes.count(b"%")
40 encoded_component = bytearray()
41
42 for i in range(0, len(uri_bytes)):
43@@ -237,7 +234,7 @@ def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
44 if (is_percent_encoded and byte == b"%") or (
45 byte_ord < 128 and byte.decode() in allowed_chars
46 ):
47- encoded_component.extend(byte)
48+ encoded_component += byte
49 continue
50 encoded_component.extend(b"%" + (hex(byte_ord)[2:].encode().zfill(2).upper()))
51
52--
532.23.0
54
diff --git a/meta-python/recipes-devtools/python/python-urllib3_1.25.6.bb b/meta-python/recipes-devtools/python/python-urllib3_1.25.6.bb
index 6c81f1db9..9f2d2c849 100644
--- a/meta-python/recipes-devtools/python/python-urllib3_1.25.6.bb
+++ b/meta-python/recipes-devtools/python/python-urllib3_1.25.6.bb
@@ -1,2 +1,4 @@
1inherit pypi setuptools 1inherit pypi setuptools
2require python-urllib3.inc 2require python-urllib3.inc
3
4SRC_URI += "file://CVE-2020-7212.patch"
diff --git a/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-7212.patch b/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-7212.patch
new file mode 100644
index 000000000..a2bb0fb5b
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-urllib3/CVE-2020-7212.patch
@@ -0,0 +1,54 @@
1From aff951b7a41eb5b958b32c49eaa00da02adc9c2d Mon Sep 17 00:00:00 2001
2From: Quentin Pradet <quentin.pradet@gmail.com>
3Date: Tue, 21 Jan 2020 22:32:56 +0400
4Subject: [PATCH] Optimize _encode_invalid_chars (#1787)
5
6Co-authored-by: Seth Michael Larson <sethmichaellarson@gmail.com>
7
8Upstream-Status: Backport
9[from git://github.com/urllib3/urllib3.git commit:a2697e7c6b]
10Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>
11---
12 src/urllib3/util/url.py | 15 ++++++---------
13 1 file changed, 6 insertions(+), 9 deletions(-)
14
15diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py
16index 9675f74..e353937 100644
17--- a/src/urllib3/util/url.py
18+++ b/src/urllib3/util/url.py
19@@ -216,18 +216,15 @@ def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
20
21 component = six.ensure_text(component)
22
23+ # Normalize existing percent-encoded bytes.
24 # Try to see if the component we're encoding is already percent-encoded
25 # so we can skip all '%' characters but still encode all others.
26- percent_encodings = PERCENT_RE.findall(component)
27-
28- # Normalize existing percent-encoded bytes.
29- for enc in percent_encodings:
30- if not enc.isupper():
31- component = component.replace(enc, enc.upper())
32+ component, percent_encodings = PERCENT_RE.subn(
33+ lambda match: match.group(0).upper(), component
34+ )
35
36 uri_bytes = component.encode("utf-8", "surrogatepass")
37- is_percent_encoded = len(percent_encodings) == uri_bytes.count(b"%")
38-
39+ is_percent_encoded = percent_encodings == uri_bytes.count(b"%")
40 encoded_component = bytearray()
41
42 for i in range(0, len(uri_bytes)):
43@@ -237,7 +234,7 @@ def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
44 if (is_percent_encoded and byte == b"%") or (
45 byte_ord < 128 and byte.decode() in allowed_chars
46 ):
47- encoded_component.extend(byte)
48+ encoded_component += byte
49 continue
50 encoded_component.extend(b"%" + (hex(byte_ord)[2:].encode().zfill(2).upper()))
51
52--
532.23.0
54
diff --git a/meta-python/recipes-devtools/python/python3-urllib3_1.25.6.bb b/meta-python/recipes-devtools/python/python3-urllib3_1.25.6.bb
index 19eb7025b..e3583a057 100644
--- a/meta-python/recipes-devtools/python/python3-urllib3_1.25.6.bb
+++ b/meta-python/recipes-devtools/python/python3-urllib3_1.25.6.bb
@@ -1,2 +1,4 @@
1inherit pypi setuptools3 1inherit pypi setuptools3
2require python-urllib3.inc 2require python-urllib3.inc
3
4SRC_URI += "file://CVE-2020-7212.patch"