Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94c5da1

Browse files
committed
[2.0.x] Fixed CVE-2018-7537 -- Fixed catastrophic backtracking in django.utils.text.Truncator.
Thanks James Davis for suggesting the fix.
1 parent e157315 commit 94c5da1

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

django/utils/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def capfirst(x):
2020
# Set up regular expressions
2121
re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.S)
2222
re_chars = re.compile(r'<.*?>|(.)', re.S)
23-
re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S)
23+
re_tag = re.compile(r'<(/)?(\S+?)(?:(\s*/)|\s.*?)?>', re.S)
2424
re_newlines = re.compile(r'\r\n|\r') # Used in normalize_newlines
2525
re_camel_case = re.compile(r'(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))')
2626

docs/releases/1.11.11.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ expressions. The ``urlize()`` function is used to implement the ``urlize`` and
1616

1717
The problematic regular expressions are replaced with parsing logic that
1818
behaves similarly.
19+
20+
CVE-2018-7537: Denial-of-service possibility in ``truncatechars_html`` and ``truncatewords_html`` template filters
21+
==================================================================================================================
22+
23+
If ``django.utils.text.Truncator``'s ``chars()`` and ``words()`` methods were
24+
passed the ``html=True`` argument, they were extremely slow to evaluate certain
25+
inputs due to a catastrophic backtracking vulnerability in a regular
26+
expression. The ``chars()`` and ``words()`` methods are used to implement the
27+
``truncatechars_html`` and ``truncatewords_html`` template filters, which were
28+
thus vulnerable.
29+
30+
The backtracking problem in the regular expression is fixed.

docs/releases/1.8.19.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ expression. The ``urlize()`` function is used to implement the ``urlize`` and
1616

1717
The problematic regular expression is replaced with parsing logic that behaves
1818
similarly.
19+
20+
CVE-2018-7537: Denial-of-service possibility in ``truncatechars_html`` and ``truncatewords_html`` template filters
21+
==================================================================================================================
22+
23+
If ``django.utils.text.Truncator``'s ``chars()`` and ``words()`` methods were
24+
passed the ``html=True`` argument, they were extremely slow to evaluate certain
25+
inputs due to a catastrophic backtracking vulnerability in a regular
26+
expression. The ``chars()`` and ``words()`` methods are used to implement the
27+
``truncatechars_html`` and ``truncatewords_html`` template filters, which were
28+
thus vulnerable.
29+
30+
The backtracking problem in the regular expression is fixed.

docs/releases/2.0.3.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ expressions. The ``urlize()`` function is used to implement the ``urlize`` and
1818
The problematic regular expressions are replaced with parsing logic that
1919
behaves similarly.
2020

21+
CVE-2018-7537: Denial-of-service possibility in ``truncatechars_html`` and ``truncatewords_html`` template filters
22+
==================================================================================================================
23+
24+
If ``django.utils.text.Truncator``'s ``chars()`` and ``words()`` methods were
25+
passed the ``html=True`` argument, they were extremely slow to evaluate certain
26+
inputs due to a catastrophic backtracking vulnerability in a regular
27+
expression. The ``chars()`` and ``words()`` methods are used to implement the
28+
``truncatechars_html`` and ``truncatewords_html`` template filters, which were
29+
thus vulnerable.
30+
31+
The backtracking problem in the regular expression is fixed.
32+
2133
Bugfixes
2234
========
2335

tests/utils_tests/test_text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def test_truncate_html_words(self):
136136
truncator = text.Truncator('<p>I &lt;3 python, what about you?</p>')
137137
self.assertEqual('<p>I &lt;3 python...</p>', truncator.words(3, '...', html=True))
138138

139+
re_tag_catastrophic_test = ('</a' + '\t' * 50000) + '//>'
140+
truncator = text.Truncator(re_tag_catastrophic_test)
141+
self.assertEqual(re_tag_catastrophic_test, truncator.words(500, html=True))
142+
139143
def test_wrap(self):
140144
digits = '1234 67 9'
141145
self.assertEqual(text.wrap(digits, 100), '1234 67 9')

0 commit comments

Comments
 (0)