Skip to content
DoS Disclosed report Intermediate CVE-2024-27351

CVE-2024-27351: Potential regular expression denial-of-service in django.utils.text.Truncator.words()

The Django Truncator.words() method with html=True and the truncatewords_html template filter used regular expressions vulnerable to catastrophic backtracking. An attacker could supply a crafted string to cause a denial-of-service by consuming excessive CPU time.

scyoon Follow

Originally disclosed on HackerOne

  • Triaged in 3 days
  • Fixed in 24 days
  • Paid in 24 days
  • Disclosed after 54 days

Summary by the program

CVE-2024-27351: Potential regular expression denial-of-service in django.utils.text.Truncator.words() django.utils.text.Truncator.words() method (with html=True) and truncatewords_html template filter were subject to a potential regular expression denial-of-service attack using a suitably crafted string (follow up to CVE-2019-14232 and CVE-2023-43665).

Thanks Seokchan Yoon for the report.

This issue has severity "moderate" according to the Django security policy.

Full Security Advisory: https://www.djangoproject.com/weblog/2024/mar/04/security-releases/

The report

TL;DR

CVE-2024-27351: Potential regular expression denial-of-service in django.utils.text.Truncator.words()

Details:

django.utils.text.Truncator.words() method (with html=True) and truncatewords_html template filter were subject to a potential regular expression denial-of-service attack using a suitably crafted string (follow up to CVE-2019-14232 and CVE-2023-43665).

  • The Truncator class truncates text based on word count.
  • When the html flag is set, the internal _truncate_html() method is used.
  • This method relies on regular expressions stored in variables (re_chars and re_words) to perform the truncation.
  • These regular expressions are vulnerable to ReDoS attacks, which can cause significant performance degradation and denial-of-service.

PoC:

Python
#!/usr/bin/env python3
from django.utils.text import Truncator
import time


MAX_LENGTH = 65535

payload = '<' * MAX_LENGTH
print('[INFO] %d bytes of payload' % len(payload))

start_time = time.time()
Truncator(payload).words(3, truncate='...', html=True) # BOOM!
end_time = time.time()

print('[INFO] Truncator().words() took %lf seconds' % (end_time - start_time))

The impact of this vulnerability may vary depending on the computing environment. In my tests using an AMD Ryzen 7 3700X with 32GB RAM, I observed a notable delay of approximately 40 seconds.

Impact

An attacker could exploit this vulnerability to:

  • Consume excessive server resources, causing performance degradation and potential service outages.
  • Delay application response times significantly.

The original report as published on HackerOne, by scyoon. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, the regular expressions used in the HTML truncation logic had nested quantifiers or ambiguous matching that allowed catastrophic backtracking on crafted input.

Impact

An attacker could cause significant delays (about 40 seconds in the reporter's test) and potentially service outages by consuming server resources.

What the attacker needed

Application uses Truncator.words() with html=True or…; attacker can supply the input string

The fix

The advisory links to Django security releases, but the text does not state a fix.

How it was found

  1. Import the Truncator class from django.utils.text.
  2. Create a string consisting of many '<' characters (e.g., 65535).
  3. Call Truncator(payload).words(3, truncate='...', html=True) and measure the time taken.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A regular expression is a pattern used to search text. Some patterns can take a very long time when given a specially crafted input, which is called a regular expression denial-of-service (ReDoS). Here, a string made of many '<' characters made Django's text truncation function run for about 40 seconds, which could slow down or crash a website.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by scyoon

View all

2 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.