Executive brief
Django is a widely-used Python web application framework. The truncatechars_html and truncatewords_html template filters, used to shorten and sanitize HTML text in web pages, contained a regular expression with catastrophic backtracking behavior. An attacker could provide specially crafted input to these filters, causing the server to consume excessive CPU resources and become unresponsive, disrupting service availability.
Technical details
The vulnerability exists in Django's django.utils.text.Truncator class, specifically in the chars() and words() methods when invoked with html=True. These methods use a regular expression susceptible to catastrophic backtracking (CWE-185), which causes exponential time complexity when processing certain malicious inputs. The vulnerable template filters—truncatechars_html and truncatewords_html—are typically reachable whenever user-controlled or attacker-influenced data is processed through these filters. No authentication is required; an attacker simply needs to send a request containing specially crafted HTML input. The fix involved replacing the vulnerable regular expression with one that does not exhibit backtracking vulnerabilities. Patches were released in Django 2.0.3, 1.11.11, and 1.8.19.
Affected products
- Django Django 1.8 before 1.8.19, 1.11 before 1.11.11, 2.0 before 2.0.3
Timeline
- 2019-01-04: disclosed: Vulnerability published via GHSA-2f9x-5v75-3qv4
- 2018-03: patched: Security releases issued: Django 1.8.19, 1.11.11, 2.0.3