Django SQL Injection Vulnerability in django
Summary
CVE-2024-42005: Django SQL injection vulnerability. Affects django across 2 version ranges.
>= 4.2, < 4.2.15
>= 5.0, < 5.0.8
Fixed in 4.2.15 or 5.0.8, depending on the release line you run. How to fix ↓
Also tracked for
- django · Bitnami
- python-django · Debian:11
The same CVE-2024-42005 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Django is a popular Python web framework known for its simplicity and versatility. It provides developers with a powerful toolkit to build web applications efficiently. However, a critical SQL injection vulnerability has been discovered in Django versions 5.0 before 5.0.8 and 4.2 before 4.2.15. This vulnerability affects models with a JSONField and can be exploited through the QuerySet.values() and values_list() methods. An attacker can inject malicious SQL code by crafting a JSON object key as a passed argument.
Vulnerability Detail
The Django SQL injection vulnerability allows an attacker to execute arbitrary SQL queries by manipulating the JSON object key passed as an argument to the QuerySet.values() and values_list() methods. This can lead to unauthorized access, data leakage, or even complete compromise of the database. The vulnerability has a CVSS score of 9.1, indicating its high severity. It is crucial to address this vulnerability promptly to protect sensitive data and ensure the integrity of the application.
How To Fix
Latest published version: 6.1.2 as of 22 Oct 2026
pip install --upgrade "django==6.1.2"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
>= 4.2, < 4.2.154.2.15pip install --upgrade "django==4.2.15" -
>= 5.0, < 5.0.85.0.8pip install --upgrade "django==5.0.8"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, developers can sanitize and validate the JSON object keys before passing them as arguments to the affected methods. By carefully validating the input and ensuring that it does not contain any malicious SQL code, the risk of exploitation can be mitigated. Here's an example of how to sanitize the JSON object key:
import re
def sanitize_json_key(key):
return re.sub(r'[^a-zA-Z0-9_]', '', key)
This code snippet removes any characters that are not alphanumeric or underscores from the JSON object key.
Conclusion
The Django SQL injection vulnerability poses a significant threat to the security of web applications built with Django. It is crucial to promptly update to the fixed versions (5.0.8 or 4.2.15) or apply the provided workaround to mitigate the risk. Regularly monitoring for vulnerabilities using tools like Vulert can help ensure the ongoing security of your application.
See every vulnerability recorded for django →
FAQ
The vulnerability allows an attacker to execute arbitrary SQL queries, potentially leading to unauthorized access, data leakage, or complete compromise of the database.
The vulnerability affects Django versions 5.0 before 5.0.8 and 4.2 before 4.2.15.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities, using only Pipfile.lock as input.
Yes, the vulnerability can be fixed by upgrading Django to version 5.0.8 or 4.2.15, depending on the currently used version.
A temporary workaround is to sanitize and validate the JSON object keys before passing them as arguments to the affected methods. This can help mitigate the risk of exploitation.
References
Related vulnerabilities
Recent vulnerabilities recorded for django.