diff options
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-django/CVE-2024-41991.patch | 122 | ||||
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-django_2.2.28.bb | 1 |
2 files changed, 123 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-django/CVE-2024-41991.patch b/meta-python/recipes-devtools/python/python3-django/CVE-2024-41991.patch new file mode 100644 index 0000000000..c050a4ad38 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-django/CVE-2024-41991.patch | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | From efea1ef7e2190e3f77ca0651b5458297bc0f6a9f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Mariusz Felisiak <felisiak.mariusz@gmail.com> | ||
| 3 | Date: Wed, 10 Jul 2024 20:30:12 +0200 | ||
| 4 | Subject: [PATCH] [4.2.x] Fixed CVE-2024-41991 -- Prevented potential ReDoS in | ||
| 5 | django.utils.html.urlize() and AdminURLFieldWidget. | ||
| 6 | |||
| 7 | Thanks Seokchan Yoon for the report. | ||
| 8 | |||
| 9 | Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | ||
| 10 | |||
| 11 | CVE: CVE-2024-41991 | ||
| 12 | |||
| 13 | Upstream-Status: Backport [https://github.com/django/django/commit/efea1ef7e2190e3f77ca0651b5458297bc0f6a9f] | ||
| 14 | |||
| 15 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
| 16 | --- | ||
| 17 | django/contrib/admin/widgets.py | 2 +- | ||
| 18 | django/utils/html.py | 10 ++++++++-- | ||
| 19 | tests/admin_widgets/tests.py | 7 ++++++- | ||
| 20 | tests/utils_tests/test_html.py | 13 +++++++++++++ | ||
| 21 | 4 files changed, 28 insertions(+), 4 deletions(-) | ||
| 22 | |||
| 23 | diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py | ||
| 24 | index a56baee..47647e8 100644 | ||
| 25 | --- a/django/contrib/admin/widgets.py | ||
| 26 | +++ b/django/contrib/admin/widgets.py | ||
| 27 | @@ -344,7 +344,7 @@ class AdminURLFieldWidget(forms.URLInput): | ||
| 28 | context = super().get_context(name, value, attrs) | ||
| 29 | context['current_label'] = _('Currently:') | ||
| 30 | context['change_label'] = _('Change:') | ||
| 31 | - context['widget']['href'] = smart_urlquote(context['widget']['value']) if value else '' | ||
| 32 | + context['widget']['href'] = smart_urlquote(context['widget']['value']) if url_valid else '' | ||
| 33 | context['url_valid'] = url_valid | ||
| 34 | return context | ||
| 35 | |||
| 36 | diff --git a/django/utils/html.py b/django/utils/html.py | ||
| 37 | index 84e157d..52a3389 100644 | ||
| 38 | --- a/django/utils/html.py | ||
| 39 | +++ b/django/utils/html.py | ||
| 40 | @@ -12,6 +12,8 @@ from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS | ||
| 41 | from django.utils.safestring import SafeData, SafeText, mark_safe | ||
| 42 | from django.utils.text import normalize_newlines | ||
| 43 | |||
| 44 | +MAX_URL_LENGTH = 2048 | ||
| 45 | + | ||
| 46 | # Configuration for urlize() function. | ||
| 47 | TRAILING_PUNCTUATION_CHARS = '.,:;!' | ||
| 48 | WRAPPING_PUNCTUATION = [('(', ')'), ('[', ']')] | ||
| 49 | @@ -353,6 +355,10 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): | ||
| 50 | except ValueError: | ||
| 51 | # value contains more than one @. | ||
| 52 | return False | ||
| 53 | + # Max length for domain name labels is 63 characters per RFC 1034. | ||
| 54 | + # Helps to avoid ReDoS vectors in the domain part. | ||
| 55 | + if len(p2) > 63: | ||
| 56 | + return False | ||
| 57 | # Dot must be in p2 (e.g. example.com) | ||
| 58 | if '.' not in p2 or p2.startswith('.'): | ||
| 59 | return False | ||
| 60 | @@ -371,9 +377,9 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): | ||
| 61 | # Make URL we want to point to. | ||
| 62 | url = None | ||
| 63 | nofollow_attr = ' rel="nofollow"' if nofollow else '' | ||
| 64 | - if simple_url_re.match(middle): | ||
| 65 | + if len(middle) <= MAX_URL_LENGTH and simple_url_re.match(middle): | ||
| 66 | url = smart_urlquote(unescape(middle)) | ||
| 67 | - elif simple_url_2_re.match(middle): | ||
| 68 | + elif len(middle) <= MAX_URL_LENGTH and simple_url_2_re.match(middle): | ||
| 69 | url = smart_urlquote('http://%s' % unescape(middle)) | ||
| 70 | elif ':' not in middle and is_email_simple(middle): | ||
| 71 | local, domain = middle.rsplit('@', 1) | ||
| 72 | diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py | ||
| 73 | index 4c14a47..e373f1a 100644 | ||
| 74 | --- a/tests/admin_widgets/tests.py | ||
| 75 | +++ b/tests/admin_widgets/tests.py | ||
| 76 | @@ -336,7 +336,12 @@ class AdminSplitDateTimeWidgetTest(SimpleTestCase): | ||
| 77 | class AdminURLWidgetTest(SimpleTestCase): | ||
| 78 | def test_get_context_validates_url(self): | ||
| 79 | w = widgets.AdminURLFieldWidget() | ||
| 80 | - for invalid in ['', '/not/a/full/url/', 'javascript:alert("Danger XSS!")']: | ||
| 81 | + for invalid in [ | ||
| 82 | + "", | ||
| 83 | + "/not/a/full/url/", | ||
| 84 | + 'javascript:alert("Danger XSS!")', | ||
| 85 | + "http://" + "한.글." * 1_000_000 + "com", | ||
| 86 | + ]: | ||
| 87 | with self.subTest(url=invalid): | ||
| 88 | self.assertFalse(w.get_context('name', invalid, {})['url_valid']) | ||
| 89 | self.assertTrue(w.get_context('name', 'http://example.com', {})['url_valid']) | ||
| 90 | diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py | ||
| 91 | index 5abab8d..1956655 100644 | ||
| 92 | --- a/tests/utils_tests/test_html.py | ||
| 93 | +++ b/tests/utils_tests/test_html.py | ||
| 94 | @@ -254,6 +254,15 @@ class TestUtilsHtml(SimpleTestCase): | ||
| 95 | ), | ||
| 96 | ('foo@example.com', '<a href="mailto:foo@example.com">foo@example.com</a>'), | ||
| 97 | ) | ||
| 98 | + ( | ||
| 99 | + "test@" + "한.글." * 15 + "aaa", | ||
| 100 | + '<a href="mailto:test@' | ||
| 101 | + + "xn--6q8b.xn--bj0b." * 15 | ||
| 102 | + + 'aaa">' | ||
| 103 | + + "test@" | ||
| 104 | + + "한.글." * 15 | ||
| 105 | + + "aaa</a>", | ||
| 106 | + ), | ||
| 107 | for value, output in tests: | ||
| 108 | with self.subTest(value=value): | ||
| 109 | self.assertEqual(urlize(value), output) | ||
| 110 | @@ -261,6 +270,10 @@ class TestUtilsHtml(SimpleTestCase): | ||
| 111 | def test_urlize_unchanged_inputs(self): | ||
| 112 | tests = ( | ||
| 113 | ('a' + '@a' * 50000) + 'a', # simple_email_re catastrophic test | ||
| 114 | + # Unicode domain catastrophic tests. | ||
| 115 | + "a@" + "한.글." * 1_000_000 + "a", | ||
| 116 | + "http://" + "한.글." * 1_000_000 + "com", | ||
| 117 | + "www." + "한.글." * 1_000_000 + "com", | ||
| 118 | ('a' + '.' * 1000000) + 'a', # trailing_punctuation catastrophic test | ||
| 119 | 'foo@', | ||
| 120 | '@foo.com', | ||
| 121 | -- | ||
| 122 | 2.40.0 | ||
diff --git a/meta-python/recipes-devtools/python/python3-django_2.2.28.bb b/meta-python/recipes-devtools/python/python3-django_2.2.28.bb index 57ab72bc90..b46fdfc42b 100644 --- a/meta-python/recipes-devtools/python/python3-django_2.2.28.bb +++ b/meta-python/recipes-devtools/python/python3-django_2.2.28.bb | |||
| @@ -20,6 +20,7 @@ SRC_URI += "file://CVE-2023-31047.patch \ | |||
| 20 | file://CVE-2024-41989-0003.patch \ | 20 | file://CVE-2024-41989-0003.patch \ |
| 21 | file://CVE-2024-41989-0004.patch \ | 21 | file://CVE-2024-41989-0004.patch \ |
| 22 | file://CVE-2024-41990.patch \ | 22 | file://CVE-2024-41990.patch \ |
| 23 | file://CVE-2024-41991.patch \ | ||
| 23 | " | 24 | " |
| 24 | 25 | ||
| 25 | SRC_URI[sha256sum] = "0200b657afbf1bc08003845ddda053c7641b9b24951e52acd51f6abda33a7413" | 26 | SRC_URI[sha256sum] = "0200b657afbf1bc08003845ddda053c7641b9b24951e52acd51f6abda33a7413" |
