An issue was discovered in 5.1 before 5.1.14, 4.2 before 4.2.26, and 5.2 before 5.2.8. The methods `QuerySet.filter()`, `QuerySet.exclude()`, and `QuerySet.get()`, and the class `Q()`, are subject to SQL injection when using a suitably crafted dictionary, with dictionary expansion, as the `_connector` argument. Earlier, unsupported Django series (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated and may also be affected. Django would like to thank cyberstan for reporting this issue.
The vulnerability affects the QuerySet.filter(), QuerySet.exclude(), and QuerySet.get() methods, as well as the Q() class. An attacker can pass a specially crafted dictionary with expansion (dictionary expansion) as the _connector argument to one of the mentioned methods. Django does not properly validate this value, allowing arbitrary SQL code injection into the generated query. The attack does not require authentication or user interaction, and the vector is network-based.
An attacker can gain unauthorized access to sensitive data stored in the database (high impact on confidentiality) and modify or delete data (high impact on integrity). The vulnerability does not directly affect system availability.
Django must be updated immediately to version 5.1.14, 4.2.26, or 5.2.8 (depending on the branch in use). Details are available in the official security advisory: https://www.djangoproject.com/weblog/2025/nov/05/security-releases/. Users of unsupported branches (e.g., 3.2.x, 4.1.x, 5.0.x) should urgently migrate to a supported version.
Django in versions: 5.1 before 5.1.14, 4.2 before 4.2.26, and 5.2 before 5.2.8. Older, unsupported branches (5.0.x, 4.1.x, 3.2.x) were not analyzed and may also be vulnerable.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:NDjangoproject Django
APPDjangoproject4.2 – 4.2.26 (excl.)5.1 – 5.1.14 (excl.)5.2 – 5.2.8 (excl.)
Related vulnerabilities
Django: brak walidacji uprawnień dodawania w GenericInlineModelAdmin
SQL Injection w Django przez HasKey lookup na bazie Oracle
Pominięcie walidacji przy wielokrotnym przesyłaniu plików w Django
SQL injection w funkcjach Trunc() i Extract() frameworka Django
SQL injection w metodach QuerySet Django przez aliasy kolumn