diff options
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-django/CVE-2024-53907.patch')
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-django/CVE-2024-53907.patch | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-django/CVE-2024-53907.patch b/meta-python/recipes-devtools/python/python3-django/CVE-2024-53907.patch new file mode 100644 index 0000000000..5a6af70611 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-django/CVE-2024-53907.patch | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | From 790eb058b0716c536a2f2e8d1c6d5079d776c22b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | ||
| 3 | Date: Wed, 13 Nov 2024 15:06:23 +0100 | ||
| 4 | Subject: [PATCH] [4.2.x] Fixed CVE-2024-53907 -- Mitigated potential DoS in | ||
| 5 | strip_tags(). | ||
| 6 | |||
| 7 | Thanks to jiangniao for the report, and Shai Berger and Natalia Bidart | ||
| 8 | for the reviews. | ||
| 9 | |||
| 10 | CVE: CVE-2024-53907 | ||
| 11 | |||
| 12 | Upstream-Status: Backport [https://github.com/django/django/commit/790eb058b0716c536a2f2e8d1c6d5079d776c22b] | ||
| 13 | |||
| 14 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
| 15 | |||
| 16 | --- | ||
| 17 | django/utils/html.py | 10 ++++++++-- | ||
| 18 | tests/utils_tests/test_html.py | 7 +++++++ | ||
| 19 | 2 files changed, 15 insertions(+), 2 deletions(-) | ||
| 20 | |||
| 21 | diff --git a/django/utils/html.py b/django/utils/html.py | ||
| 22 | index 3cf1bfc..0d5ffd2 100644 | ||
| 23 | --- a/django/utils/html.py | ||
| 24 | +++ b/django/utils/html.py | ||
| 25 | @@ -8,12 +8,14 @@ from urllib.parse import ( | ||
| 26 | parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit, | ||
| 27 | ) | ||
| 28 | |||
| 29 | +from django.core.exceptions import SuspiciousOperation | ||
| 30 | from django.utils.functional import Promise, keep_lazy, keep_lazy_text | ||
| 31 | from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS | ||
| 32 | from django.utils.safestring import SafeData, SafeText, mark_safe | ||
| 33 | from django.utils.text import normalize_newlines | ||
| 34 | |||
| 35 | MAX_URL_LENGTH = 2048 | ||
| 36 | +MAX_STRIP_TAGS_DEPTH = 50 | ||
| 37 | |||
| 38 | # Configuration for urlize() function. | ||
| 39 | TRAILING_PUNCTUATION_CHARS = '.,:;!' | ||
| 40 | @@ -185,15 +187,19 @@ def _strip_once(value): | ||
| 41 | @keep_lazy_text | ||
| 42 | def strip_tags(value): | ||
| 43 | """Return the given HTML with all tags stripped.""" | ||
| 44 | - # Note: in typical case this loop executes _strip_once once. Loop condition | ||
| 45 | - # is redundant, but helps to reduce number of executions of _strip_once. | ||
| 46 | value = str(value) | ||
| 47 | + # Note: in typical case this loop executes _strip_once twice (the second | ||
| 48 | + # execution does not remove any more tags). | ||
| 49 | + strip_tags_depth = 0 | ||
| 50 | while '<' in value and '>' in value: | ||
| 51 | + if strip_tags_depth >= MAX_STRIP_TAGS_DEPTH: | ||
| 52 | + raise SuspiciousOperation | ||
| 53 | new_value = _strip_once(value) | ||
| 54 | if value.count('<') == new_value.count('<'): | ||
| 55 | # _strip_once wasn't able to detect more tags. | ||
| 56 | break | ||
| 57 | value = new_value | ||
| 58 | + strip_tags_depth += 1 | ||
| 59 | return value | ||
| 60 | |||
| 61 | |||
| 62 | diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py | ||
| 63 | index 8fe2f24..2f412e1 100644 | ||
| 64 | --- a/tests/utils_tests/test_html.py | ||
| 65 | +++ b/tests/utils_tests/test_html.py | ||
| 66 | @@ -1,6 +1,7 @@ | ||
| 67 | import os | ||
| 68 | from datetime import datetime | ||
| 69 | |||
| 70 | +from django.core.exceptions import SuspiciousOperation | ||
| 71 | from django.test import SimpleTestCase | ||
| 72 | from django.utils.functional import lazystr | ||
| 73 | from django.utils.html import ( | ||
| 74 | @@ -90,12 +91,18 @@ class TestUtilsHtml(SimpleTestCase): | ||
| 75 | ('<script>alert()</script>&h', 'alert()h'), | ||
| 76 | ('><!' + ('&' * 16000) + 'D', '><!' + ('&' * 16000) + 'D'), | ||
| 77 | ('X<<<<br>br>br>br>X', 'XX'), | ||
| 78 | + ("<" * 50 + "a>" * 50, ""), | ||
| 79 | ) | ||
| 80 | for value, output in items: | ||
| 81 | with self.subTest(value=value, output=output): | ||
| 82 | self.check_output(strip_tags, value, output) | ||
| 83 | self.check_output(strip_tags, lazystr(value), output) | ||
| 84 | |||
| 85 | + def test_strip_tags_suspicious_operation(self): | ||
| 86 | + value = "<" * 51 + "a>" * 51, "<a>" | ||
| 87 | + with self.assertRaises(SuspiciousOperation): | ||
| 88 | + strip_tags(value) | ||
| 89 | + | ||
| 90 | def test_strip_tags_files(self): | ||
| 91 | # Test with more lengthy content (also catching performance regressions) | ||
| 92 | for filename in ('strip_tags1.html', 'strip_tags2.txt'): | ||
