CVE-2022-34265: SQL Injection Vulnerability in Django
Summary
CVE-2022-34265: An issue was discovered in Django 3.2 before 3.2.14 and 4.0 before 4.0.6. Affects django across 2 version ranges.
>= 3.2, < 3.2.14
>= 4.0, < 4.0.6
Fixed in 3.2.14 or 4.0.6, depending on the release line you run. How to fix ↓
Also tracked for
- django · Bitnami
- python-django · Debian:11
The same CVE-2022-34265 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 scalability. It provides a robust set of tools and features for building web applications. However, Django versions 3.2 before 3.2.14 and 4.0 before 4.0.6 are susceptible to a SQL injection vulnerability. This vulnerability affects the Trunc() and Extract() database functions when untrusted data is used as a kind/lookup_name value. Applications that do not constrain the lookup name and kind choice to a known safe list may be impacted.
Vulnerability Detail
The SQL injection vulnerability in Django allows an attacker to manipulate database queries by injecting malicious SQL code. By exploiting this vulnerability, an attacker can execute arbitrary SQL commands, potentially gaining unauthorized access to sensitive data, modifying or deleting data, or even compromising the entire application. It is crucial to address this vulnerability promptly to prevent any potential security breaches.
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.
-
>= 3.2, < 3.2.143.2.14pip install --upgrade "django==3.2.14" -
>= 4.0, < 4.0.64.0.6pip install --upgrade "django==4.0.6"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading Django is not immediately feasible, a temporary workaround can be implemented by ensuring that the kind/lookup_name values used in the Trunc() and Extract() functions are constrained to a known safe list. By validating and sanitizing user input, you can mitigate the risk of SQL injection attacks. Here's an example of how to implement this workaround in Python:
# Define a list of safe lookup names
safe_lookup_names = ['name', 'date', 'id']
# Validate and sanitize user input
lookup_name = request.GET.get('lookup_name')
if lookup_name in safe_lookup_names:
# Perform database query using the validated lookup_name
results = MyModel.objects.annotate(truncated=Trunc('date', lookup_name))
...
else:
# Handle invalid lookup_name
...
By explicitly checking if the lookup_name is in the safe_lookup_names list, you can prevent untrusted input from being used in the vulnerable functions.
Conclusion
The SQL injection vulnerability in Django versions 3.2 before 3.2.14 and 4.0 before 4.0.6 can have severe consequences if left unaddressed. It is crucial to upgrade to the fixed versions or implement the provided workaround to mitigate the risk of SQL injection attacks. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for django →
FAQ
This vulnerability allows an attacker to execute arbitrary SQL commands, potentially leading to unauthorized access, data manipulation, or application compromise.
Django versions 3.2 before 3.2.14 and 4.0 before 4.0.6 are affected by this vulnerability.
Yes, applications that constrain the lookup name and kind choice to a known safe list are not impacted by this vulnerability.
Yes, a temporary workaround involves validating and sanitizing user input to ensure that only safe lookup names are used in the vulnerable functions.
The recommended fix is to upgrade Django to version 3.2.14 or 4.0.6, which include patches to address the SQL injection vulnerability.
Related vulnerabilities
Recent vulnerabilities recorded for django.