CVE-2022-34265: SQL Injection Vulnerability in Django

django Updated 02 Oct 2025

Summary

04/07/2022
Yes i
Critical
9.8

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

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

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.14 3.2.14
    pip install --upgrade "django==3.2.14"
  • >= 4.0, < 4.0.6 4.0.6
    pip 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 →

Share this vulnerability

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.

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.14 3.2.14
    pip install --upgrade "django==3.2.14"
  • >= 4.0, < 4.0.6 4.0.6
    pip 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback