Django SQL Injection Vulnerability in django

django Updated 02 Oct 2025

Summary

07/08/2024
Yes i
Critical
9.1

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

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.

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

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 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.15 4.2.15
    pip install --upgrade "django==4.2.15"
  • >= 5.0, < 5.0.8 5.0.8
    pip 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 →

Share this vulnerability

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.

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.

  • >= 4.2, < 4.2.15 4.2.15
    pip install --upgrade "django==4.2.15"
  • >= 5.0, < 5.0.8 5.0.8
    pip 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 →

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