File tree Expand file tree Collapse file tree 7 files changed +46
–9
lines changed
template_tests/filter_tests Expand file tree Collapse file tree 7 files changed +46
–9
lines changed Original file line number Diff line number Diff line change @@ -434,14 +434,17 @@ def trim_punctuation(self, word):
434434 potential_entity = middle [amp :]
435435 escaped = html .unescape (potential_entity )
436436 if escaped == potential_entity or escaped .endswith (";" ):
437- rstripped = middle .rstrip (";" )
438- amount_stripped = len (middle ) - len (rstripped )
439- if amp > - 1 and amount_stripped > 1 :
440- # Leave a trailing semicolon as might be an entity.
441- trail = middle [len (rstripped ) + 1 :] + trail
442- middle = rstripped + ";"
437+ rstripped = middle .rstrip (self .trailing_punctuation_chars )
438+ trail_start = len (rstripped )
439+ amount_trailing_semicolons = len (middle ) - len (middle .rstrip (";" ))
440+ if amp > - 1 and amount_trailing_semicolons > 1 :
441+ # Leave up to most recent semicolon as might be an entity.
442+ recent_semicolon = middle [trail_start :].index (";" )
443+ middle_semicolon_index = recent_semicolon + trail_start + 1
444+ trail = middle [middle_semicolon_index :] + trail
445+ middle = rstripped + middle [trail_start :middle_semicolon_index ]
443446 else :
444- trail = middle [len ( rstripped ) :] + trail
447+ trail = middle [trail_start :] + trail
445448 middle = rstripped
446449 trimmed_something = True
447450
Original file line number Diff line number Diff line change @@ -2922,6 +2922,17 @@ Django's built-in :tfilter:`escape` filter. The default value for
29222922 email addresses that contain single quotes (``'``), things won't work as
29232923 expected. Apply this filter only to plain text.
29242924
2925+ .. warning::
2926+
2927+ Using ``urlize`` or ``urlizetrunc`` can incur a performance penalty, which
2928+ can become severe when applied to user controlled values such as content
2929+ stored in a :class:`~django.db.models.TextField`. You can use
2930+ :tfilter:`truncatechars` to add a limit to such inputs:
2931+
2932+ .. code-block:: html+django
2933+
2934+ {{ value|truncatechars:500|urlize }}
2935+
29252936.. templatefilter:: urlizetrunc
29262937
29272938``urlizetrunc``
Original file line number Diff line number Diff line change @@ -7,4 +7,9 @@ Django 4.2.16 release notes
77Django 4.2.16 fixes one security issue with severity "moderate" and one
88security issue with severity "low" in 4.2.15.
99
10- ...
10+ CVE-2024-45230: Potential denial-of-service vulnerability in ``django.utils.html.urlize()``
11+ ===========================================================================================
12+
13+ :tfilter:`urlize` and :tfilter:`urlizetrunc` were subject to a potential
14+ denial-of-service attack via very large inputs with a specific sequence of
15+ characters.
Original file line number Diff line number Diff line change @@ -7,4 +7,9 @@ Django 5.0.9 release notes
77Django 5.0.9 fixes one security issue with severity "moderate" and one security
88issue with severity "low" in 5.0.8.
99
10- ...
10+ CVE-2024-45230: Potential denial-of-service vulnerability in ``django.utils.html.urlize()``
11+ ===========================================================================================
12+
13+ :tfilter:`urlize` and :tfilter:`urlizetrunc` were subject to a potential
14+ denial-of-service attack via very large inputs with a specific sequence of
15+ characters.
Original file line number Diff line number Diff line change @@ -7,6 +7,13 @@ Django 5.1.1 release notes
77Django 5.1.1 fixes one security issue with severity "moderate", one security
88issue with severity "low", and several bugs in 5.1.
99
10+ CVE-2024-45230: Potential denial-of-service vulnerability in ``django.utils.html.urlize()``
11+ ===========================================================================================
12+
13+ :tfilter:`urlize` and :tfilter:`urlizetrunc` were subject to a potential
14+ denial-of-service attack via very large inputs with a specific sequence of
15+ characters.
16+
1017Bugfixes
1118========
1219
Original file line number Diff line number Diff line change @@ -321,6 +321,11 @@ def test_trailing_semicolon(self):
321321 '<a href="http://example.com?x=" rel="nofollow">'
322322 "http://example.com?x=&</a>;;" ,
323323 )
324+ self .assertEqual (
325+ urlize ("http://example.com?x=&.;...;" , autoescape = False ),
326+ '<a href="http://example.com?x=" rel="nofollow">'
327+ "http://example.com?x=&</a>.;...;" ,
328+ )
324329
325330 def test_brackets (self ):
326331 """
Original file line number Diff line number Diff line change @@ -396,6 +396,7 @@ def test_urlize_unchanged_inputs(self):
396396 "&:" + ";" * 100_000 ,
397397 "&.;" * 100_000 ,
398398 ".;" * 100_000 ,
399+ "&" + ";:" * 100_000 ,
399400 )
400401 for value in tests :
401402 with self .subTest (value = value ):
You can’t perform that action at this time.
0 commit comments