diff options
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-django/CVE-2023-41164.patch')
-rw-r--r-- | meta-python/recipes-devtools/python/python3-django/CVE-2023-41164.patch | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-django/CVE-2023-41164.patch b/meta-python/recipes-devtools/python/python3-django/CVE-2023-41164.patch new file mode 100644 index 0000000000..9bc38b0cca --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-django/CVE-2023-41164.patch | |||
@@ -0,0 +1,105 @@ | |||
1 | From 9c95e8fec62153f8dfcc45a70b8a68d74333a66f Mon Sep 17 00:00:00 2001 | ||
2 | From: Mariusz Felisiak <felisiak.mariusz@gmail.com> | ||
3 | Date: Tue, 26 Sep 2023 10:23:30 +0000 | ||
4 | Subject: [PATCH] Fixed CVE-2023-41164 -- Fixed potential DoS in | ||
5 | django.utils.encoding.uri_to_iri(). | ||
6 | |||
7 | Thanks MProgrammer (https://hackerone.com/mprogrammer) for the report. | ||
8 | |||
9 | Co-authored-by: nessita <124304+nessita@users.noreply.github.com> | ||
10 | |||
11 | CVE: CVE-2023-41164 | ||
12 | |||
13 | Upstream-Status: Backport [https://github.com/django/django/commit/3f41d6d62929dfe53eda8109b3b836f26645bdce] | ||
14 | |||
15 | Signed-off-by: Narpat Mali <narpat.mali@windriver.com> | ||
16 | --- | ||
17 | django/utils/encoding.py | 6 ++++-- | ||
18 | docs/releases/2.2.28.txt | 9 +++++++++ | ||
19 | tests/utils_tests/test_encoding.py | 21 ++++++++++++++++++++- | ||
20 | 3 files changed, 33 insertions(+), 3 deletions(-) | ||
21 | |||
22 | diff --git a/django/utils/encoding.py b/django/utils/encoding.py | ||
23 | index 98da647..3769702 100644 | ||
24 | --- a/django/utils/encoding.py | ||
25 | +++ b/django/utils/encoding.py | ||
26 | @@ -225,6 +225,7 @@ def repercent_broken_unicode(path): | ||
27 | repercent-encode any octet produced that is not part of a strictly legal | ||
28 | UTF-8 octet sequence. | ||
29 | """ | ||
30 | + changed_parts = [] | ||
31 | while True: | ||
32 | try: | ||
33 | path.decode() | ||
34 | @@ -232,9 +233,10 @@ def repercent_broken_unicode(path): | ||
35 | # CVE-2019-14235: A recursion shouldn't be used since the exception | ||
36 | # handling uses massive amounts of memory | ||
37 | repercent = quote(path[e.start:e.end], safe=b"/#%[]=:;$&()+,!?*@'~") | ||
38 | - path = path[:e.start] + force_bytes(repercent) + path[e.end:] | ||
39 | + changed_parts.append(path[: e.start] + repercent.encode()) | ||
40 | + path = path[e.end :] | ||
41 | else: | ||
42 | - return path | ||
43 | + return b"".join(changed_parts) + path | ||
44 | |||
45 | |||
46 | def filepath_to_uri(path): | ||
47 | diff --git a/docs/releases/2.2.28.txt b/docs/releases/2.2.28.txt | ||
48 | index ab4884b..40eb230 100644 | ||
49 | --- a/docs/releases/2.2.28.txt | ||
50 | +++ b/docs/releases/2.2.28.txt | ||
51 | @@ -47,3 +47,12 @@ CVE-2023-36053: Potential regular expression denial of service vulnerability in | ||
52 | ``EmailValidator`` and ``URLValidator`` were subject to potential regular | ||
53 | expression denial of service attack via a very large number of domain name | ||
54 | labels of emails and URLs. | ||
55 | + | ||
56 | +Backporting the CVE-2023-41164 fix on Django 2.2.28. | ||
57 | + | ||
58 | +CVE-2023-41164: Potential denial of service vulnerability in ``django.utils.encoding.uri_to_iri()`` | ||
59 | +=================================================================================================== | ||
60 | + | ||
61 | +``django.utils.encoding.uri_to_iri()`` was subject to potential denial of | ||
62 | +service attack via certain inputs with a very large number of Unicode | ||
63 | +characters. | ||
64 | diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py | ||
65 | index ea7ba5f..93a3162 100644 | ||
66 | --- a/tests/utils_tests/test_encoding.py | ||
67 | +++ b/tests/utils_tests/test_encoding.py | ||
68 | @@ -1,8 +1,9 @@ | ||
69 | import datetime | ||
70 | +import inspect | ||
71 | import sys | ||
72 | import unittest | ||
73 | from unittest import mock | ||
74 | -from urllib.parse import quote_plus | ||
75 | +from urllib.parse import quote, quote_plus | ||
76 | |||
77 | from django.test import SimpleTestCase | ||
78 | from django.utils.encoding import ( | ||
79 | @@ -100,6 +101,24 @@ class TestEncodingUtils(SimpleTestCase): | ||
80 | except RecursionError: | ||
81 | self.fail('Unexpected RecursionError raised.') | ||
82 | |||
83 | + def test_repercent_broken_unicode_small_fragments(self): | ||
84 | + data = b"test\xfctest\xfctest\xfc" | ||
85 | + decoded_paths = [] | ||
86 | + | ||
87 | + def mock_quote(*args, **kwargs): | ||
88 | + # The second frame is the call to repercent_broken_unicode(). | ||
89 | + decoded_paths.append(inspect.currentframe().f_back.f_locals["path"]) | ||
90 | + return quote(*args, **kwargs) | ||
91 | + | ||
92 | + with mock.patch("django.utils.encoding.quote", mock_quote): | ||
93 | + self.assertEqual(repercent_broken_unicode(data), b"test%FCtest%FCtest%FC") | ||
94 | + | ||
95 | + # decode() is called on smaller fragment of the path each time. | ||
96 | + self.assertEqual( | ||
97 | + decoded_paths, | ||
98 | + [b"test\xfctest\xfctest\xfc", b"test\xfctest\xfc", b"test\xfc"], | ||
99 | + ) | ||
100 | + | ||
101 | |||
102 | class TestRFC3987IEncodingUtils(unittest.TestCase): | ||
103 | |||
104 | -- | ||
105 | 2.40.0 | ||