Skip to content

Commit 11243cc

Browse files
committed
[5.1.x] Added security guideline on reasonable size limitations when rendering content via the DTL.
This also removes the need to add warnings for every Django template filter. Backport of 582ba18 from main.
1 parent b80288a commit 11243cc

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

docs/internals/security.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,32 @@ Django contains many private and undocumented functions that are not part of
168168
its public API. If a vulnerability depends on directly calling these internal
169169
functions in an unsafe way, it will not be considered a valid security issue.
170170

171+
Content displayed by the Django Template Language must be under 100 KB
172+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173+
174+
The Django Template Language (DTL) is designed for building the content needed
175+
to display web pages. In particular its text filters are meant for that kind of
176+
usage.
177+
178+
For reference, the complete works of Shakespeare have about 3.5 million bytes
179+
in plain-text ASCII encoding. Displaying such in a single request is beyond the
180+
scope of almost all websites, and so outside the scope of the DTL too.
181+
182+
Text processing is expensive. Django makes no guarantee that DTL text filters
183+
are never subject to degraded performance if passed deliberately crafted,
184+
sufficiently large inputs. Under default configurations, Django makes it
185+
difficult for sites to accidentally accept such payloads from untrusted
186+
sources, but, if it is necessary to display large amounts of user-provided
187+
content, it’s important that basic security measures are taken.
188+
189+
User-provided content should always be constrained to known maximum length. It
190+
should be filtered to remove malicious content, and validated to match expected
191+
formats. It should then be processed offline, if necessary, before being
192+
displayed.
193+
194+
Proof of concepts which use over 100 KB of data to be processed by the DTL will
195+
be considered invalid.
196+
171197
.. _security-report-evaluation:
172198

173199
How does Django evaluate a report

docs/ref/templates/builtins.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,17 +2932,6 @@ Django's built-in :tfilter:`escape` filter. The default value for
29322932
email addresses that contain single quotes (``'``), things won't work as
29332933
expected. Apply this filter only to plain text.
29342934

2935-
.. warning::
2936-
2937-
Using ``urlize`` or ``urlizetrunc`` can incur a performance penalty, which
2938-
can become severe when applied to user controlled values such as content
2939-
stored in a :class:`~django.db.models.TextField`. You can use
2940-
:tfilter:`truncatechars` to add a limit to such inputs:
2941-
2942-
.. code-block:: html+django
2943-
2944-
{{ value|truncatechars:500|urlize }}
2945-
29462935
.. templatefilter:: urlizetrunc
29472936

29482937
``urlizetrunc``

0 commit comments

Comments
 (0)