CVE-2021-35042 SQL Injection in Django
Attackers can execute arbitrary SQL commands via untrusted input in QuerySet.order_by, potentially reading or modifying database contents.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Over the internet
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2021-35042?
CVE-2021-35042 is a critical SQL injection vulnerability in Djangoproject Django, published on 2 Jul 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.
Official description
Django 3.1.x before 3.1.13 and 3.2.x before 3.2.5 allows QuerySet.order_by SQL injection if order_by is untrusted input from a client of a web application.
Weakness: CWE-89
Which versions are affected by CVE-2021-35042?
6 open source packages ship an affected version, including django and Django. It affects 2 products.
| Package | Affected | Fixed in |
|---|---|---|
django Bitnami | From 3.1.0 | 3.1.13, 3.2.5 |
django PyPI | From 3.0a1 | 3.1.13 |
django PyPI | From 3.1 | 3.1.13, 3.2.5 |
django PyPI | From 3.2a1 | 3.2.5 |
Django PyPI | From 3.0a1 | 3.1.13 |
Django PyPI | From 3.2a1 | 3.2.5 |
Products include Djangoproject Django, Fedoraproject Fedora.
How do I fix CVE-2021-35042?
Upgrade django to a fixed version for your release line: 3.1.13 or 3.2.5.
Use parameterised queries everywhere and never build SQL by joining strings. Upgrade affected software first; a web application firewall only buys time. More about SQL injection.
Is CVE-2021-35042 being exploited?
There is no known exploitation of CVE-2021-35042 in the wild and no public exploit code.
Public exploit code: 6 proofs of concept on GitHub.
Other vulnerabilities in Djangoproject Django
- CVE-2026-4277 Privilege abuse in GenericInlineModelAdmin
- CVE-2024-53908 Django SQL injection in HasKey(lhs, rhs) on Oracle
- CVE-2024-42005 Django SQL injection vulnerability
- CVE-2023-31047 Django bypasses validation when using one form field to upload multiple files
- CVE-2022-34265 Django `Trunc()` and `Extract()` database functions vulnerable to SQL Injection
Sources
Also known as BIT-django-2021-35042, GHSA-xpfp-f569-q3p2, PYSEC-2021-109.