Skip to main content

Django CVE-2025-59681

| EUVDEUVD-2025-32691 CRITICAL
SQL Injection (CWE-89)
2025-10-01 cve@mitre.org GHSA-hpr9-3m2g-3j9p
Critical
Disputed · 9.8 NVD
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Submit crafted dictionary keys via application input
  2. Delivery
    Keys expanded as **kwargs into annotate()/extra()
  3. Exploit
    Malicious alias bypasses FORBIDDEN_ALIAS_PATTERN filter
  4. Execution
    Injected SQL executes on MySQL/MariaDB
  5. Impact
    Exfiltrate or tamper with database data

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Parameterized queries, prepared statements
MITRE ATT&CK

2 techniques across 2 tactics: Initial Access, Persistence

The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up.

Exploitation Conditions

Exploitation requires an application to pass an attacker-controlled dictionary, via dictionary expansion (**kwargs), into QuerySet.annotate(), QuerySet.alias(), QuerySet.aggregate(), or QuerySet.extra(), such that untrusted input becomes a column alias; and the database backend must be MySQL or MariaDB (PostgreSQL, SQLite, and Oracle are not affected). The running Django version must be 4.2 <4.2.25, 5.1 <5.1.13, or 5.2 <5.2.7. Key limiting factors: in idiomatic Django code column aliases are hardcoded by developers rather than taken from user input, so the vulnerable pattern is uncommon; the backend restriction to MySQL/MariaDB further narrows exposure; no authentication or user interaction is required (PR:N/UI:N) once a vulnerable code path is reachable.

Impact

The input CVSS vector (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H, base 9.8) rates this as critical network-exploitable, unauthenticated SQL injection with full confidentiality, integrity, and availability impact, and the PR:N metric confirms no authentication is required at the protocol level. However, these raw-severity signals conflict sharply with the real-world exploitation signals: EPSS is only 0.01% (2nd percentile), there is no CISA KEV listing (not actively exploited), and no public exploit code was identified in the provided data. The decisive nuance the CVSS score hides is the exploitation precondition - the flaw only triggers when an application passes an attacker-controlled dictionary via dictionary expansion as the **kwargs to QuerySet.annotate()/alias()/aggregate()/extra(), AND only on MySQL/MariaDB backends. In typical Django code, column aliases are developer-defined constants, not user input, so most deployments are not exploitable despite running an affected version. This is therefore a genuinely serious library defect that warrants prompt patching (it is a follow-up to CVE-2022-28346), but for the large majority of deployments it is a high-CVSS / low-realistic-risk issue rather than a mass-exploitation priority; the near-zero EPSS and absence of KEV/POC corroborate that assessment.

Exploit ScenarioDerived

A Django web application on a MySQL or MariaDB backend takes a user-supplied dictionary (e.g. derived from request parameters) and expands it as **kwargs into QuerySet.annotate() or .extra(), letting an attacker control the column alias string. The attacker crafts a key containing percent signs or hash characters (which the pre-patch FORBIDDEN_ALIAS_PATTERN failed to block) to break out of the alias context and inject SQL, reading or modifying database contents. No public exploit code was identified at time of analysis, and exploitation depends on this uncommon coding pattern rather than default behavior.

Act Now Prioritize within 24-48h. Why: CRITICAL severity.
Patch available 0.0% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv2 – Oct 12, 2026

SQL injection in the Django ORM column-alias handling used by QuerySet.annotate(), QuerySet.alias(), QuerySet.aggregate(), and QuerySet.extra() affects Django 4.2 before 4.2.25, 5.1 before 5.1.13, and 5.2 before 5.2.7, but only when the application is backed by MySQL or MariaDB; PostgreSQL, SQLite, and Oracle are not affected. An attacker can only reach the flaw if the application itself expands an attacker-controlled dictionary (**kwargs) into those methods so that untrusted input becomes a column alias - a pattern that is uncommon in idiomatic Django code, which is why the independent assessment raises attack complexity to AC:H even though the published vector is 9.8/AC:L. Per the CVSS vector (PR:N/UI:N) no authentication or user interaction is required once that vulnerable code path exists, and the outcome is full read/write access to query data via injected SQL; at the time of analysis no public exploit code was identified and EPSS is negligible (0.01%, 2nd percentile), with vendor patches available. This is a follow-up to CVE-2022-28346, indicating the earlier alias denylist was incomplete.

Earlier versions of this analysis (1)
v1 Mar 13, 2026 - 18:18 CVSS 7.1

RemediationAI

Vendor-released patch: upgrade to Django 4.2.25, 5.1.13, or 5.2.7 (or later in each branch) as documented in https://www.djangoproject.com/weblog/2025/oct/01/security-releases/ and https://docs.djangoproject.com/en/dev/releases/security/; packaged installations should instead take the distribution build - USN-7794-1 for Ubuntu, DLA-4324-1 / DSA-6117-1 / DSA-6136-1 for Debian, RHSA-2025:18984 for Red Hat - since distro backports may carry different version numbers than upstream. Where immediate patching is impossible, the effective compensating control is to change application code, not the network layer: never pass user-controlled keys through dictionary expansion into annotate(), alias(), aggregate(), or extra(); wrap such calls behind an allowlist of hardcoded alias names and reject or normalize any key containing '#', whitespace, quotes, semicolons, percent signs, or SQL comment sequences before it reaches the ORM. This is the same validation posture as the earlier CVE-2022-28346 guidance, and because it is code-level it has no runtime side effects, though it requires auditing every dynamic call site. Migrating the affected workload to PostgreSQL, SQLite, or Oracle also removes exposure to this specific flaw but is usually a much larger operational change and may alter query semantics elsewhere. Note one patch side effect: version 4.2.25/5.1.13/5.2.7 now raises a ValueError for column aliases containing '#', so any legitimate code or test suite that previously used such aliases will fail after upgrading and must be adjusted. There is no indication of in-the-wild exploitation, so prioritization can follow normal risk-based patching, with MySQL/MariaDB-backed Django services that accept dynamic alias input treated as the highest queue.

Affected VersionsENISA

Django 4.2 <4.2.25
Django 5.1 <5.1.13
Django 5.2 <5.2.7

Affected Packages

pypi django fix: 4.2.25, 5.1.13, 5.2.1+echo.1, 5.2.7

Source: OSV (Open Source Vulnerabilities)

Affects your stack

Affects 1 package in pypi

Checking this CVE against your own stacks and servers is part of the Basic plan and up.

Technical ContextAI · show details

Root cause is CWE-89 (SQL injection) in Django's database-layer alias validation. Django builds column aliases for annotate()/alias()/aggregate()/extra() from keyword-argument names; when a caller uses dictionary expansion, the keys become alias strings that flow into generated SQL. Django maintained a denylist regex (ForbiddenAliasPattern) to prevent dangerous characters in aliases, but the MySQL/MariaDB backend quoting context made certain characters - specifically the hash sign '#' - able to terminate or comment out the surrounding alias, yielding injectable SQL. The upstream fix (commits 41b43c74bda19753c757036673ea9db74acf494a and 43d84aef04a9e71164c21a74885996981857e66e) extends the pattern to r"['`\"\]\[;\s]|#|--|/\*|\*/" and updates the error text to mention hashes, rejecting aliases such as "ali#as"; tests in tests/annotations/tests.py and tests/aggregation/tests.py were updated accordingly. The vulnerability is a follow-up to CVE-2022-28346, the same class of alias-based SQL injection that a previous denylist round failed to fully close. CPE data (cpe:2.3:a:djangoproject:django) confirms the Django project itself as the affected component rather than any third-party plugin, and the flaw is backend-specific: only MySQL and MariaDB interpret the offending character in a way that permits injection, so the exposure surface is jointly determined by Django version and database backend. The independent assessment rates this AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H, lower-complexity than the published AC:L because exploitation hinges on an application-level coding pattern (attacker-controlled keys passed via **kwargs) rather than a directly reachable network endpoint.

Know when Django gets its next vulnerability

  • Watch products and get an email when something new is published
  • Check this CVE against your own stack and servers
  • Exploit and PoC references, threat intelligence from 22 sources

No credit card · 7-day full trial

Severity by source

Sources disagree (Medium–Critical)
NVD PRIMARY 9.8 CRITICAL
AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
vuln.today AI 8.1 HIGH

SQL injection with full C/I/A impact and no auth (PR:N), but AC:H because it depends on the uncommon pattern of user-controlled aliases via **kwargs and a MySQL/MariaDB backend.

3.1 AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
4.0 AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
Ubuntu MEDIUM
SUSE 7.1 HIGH
AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:L/A:N
Red Hat 8.1 HIGH

vuln.today treats the vendor’s rating as authoritative. A higher third-party CVSS (e.g. CISA-ADP) is shown for transparency but does not drive the headline severity.

CVSS VectorNVD

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

Lifecycle Timeline

5
Severity Changed
Oct 12, 2026 - 15:22 NVD
HIGH CRITICAL
CVSS changed
Oct 12, 2026 - 15:22 NVD
7.1 (HIGH) 9.8 (CRITICAL)
Patch released
Mar 31, 2026 - 21:13 nvd
Patch available
CVE Published
Oct 01, 2025 - 19:15 nvd
CRITICAL 9.8
CVE Published
Oct 01, 2025 - 19:15 nvd
HIGH 7.1

DescriptionNVD

An issue was discovered in Django 4.2 before 4.2.25, 5.1 before 5.1.13, and 5.2 before 5.2.7. QuerySet.annotate(), QuerySet.alias(), QuerySet.aggregate(), and QuerySet.extra() are subject to SQL injection in column aliases, when using a suitably crafted dictionary, with dictionary expansion, as the **kwargs passed to these methods (on MySQL and MariaDB).

Executive ViewAI

Why It Matters

Organizations using Django 4.2 face moderate risk from CVE-2025-59681, a SQL injection vulnerability rated CVSS 7.1. Successful exploitation could allow attackers to execute arbitrary code or commands on affected systems, potentially leading to full system compromise. Organizations should apply vendor updates when available and consider compensating controls in the interim.

Business Impact: Moderate
Compensating Controls

Apply vendor patch. If immediate patching is not feasible: (1) Deploy WAF rules to block injection patterns; (2) Restrict network access to affected components; (3) Enable enhanced logging for suspicious activity.

Threat Intelligence Overview

EPSS Score
0.0%
Top 98% exploitable
Prevalence
High
Django is a very widely deployed enterprise and web application framework
Threat Intel
1
1 source
Data Quality
6 sources
Confidence: High

How this decision was reached

The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.

SignalValue
Severity CRITICAL
CISA KEV No
Public POC No
EPSS 0.0%
Patch available Yes
Active threat No
Deciding rule
CRITICAL severity
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

Exploitation· derived
None
System Exposure· derived
Open
Automatable· derived
Yes

Priority Score

49
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +49
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

SQL injection exploits the way applications construct database queries by mixing user input directly into SQL statements.

More in Django

View all
CVE-2021-23336 MEDIUM POC
5.9 Feb 15

The package python/cpython from 0 and before 3.6.13, from 3.7.0 and before 3.7.10, from 3.8.0 and before 3.8.8, from 3.9

CVE-2017-12794 MEDIUM POC
6.1 Sep 07

In Django 1.10.x before 1.10.8 and 1.11.x before 1.11.5, HTML autoescaping was disabled in a portion of the template for

CVE-2022-34265 CRITICAL POC
9.8 Jul 04

An issue was discovered in Django 3.2 before 3.2.14 and 4.0 before 4.0.6. Rated critical severity (CVSS 9.8), this vulne

CVE-2021-35042 CRITICAL POC
9.8 Jul 02

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

CVE-2019-19844 CRITICAL POC
9.8 Dec 18

Django before 1.11.27, 2.x before 2.2.9, and 3.x before 3.0.1 allows account takeover. Rated critical severity (CVSS 9.8

CVE-2026-61594 CRITICAL POC
9.1 Sep 16

An authentication/authorization bypass in the djust Python live-view framework (versions prior to 1.0.7) lets unauthenti

CVE-2026-61599 HIGH POC
8.8 Sep 16

Unauthenticated arbitrary Python module import in djust before 1.0.7 lets any client that can reach the WebSocket or SSE

CVE-2020-9402 HIGH POC
8.8 Mar 05

Django 1.11 before 1.11.29, 2.2 before 2.2.11, and 3.0 before 3.0.4 allows SQL Injection if untrusted data is used as a

CVE-2016-6186 MEDIUM POC
6.1 Aug 05

Cross-site scripting (XSS) vulnerability in the dismissChangeRelatedObjectPopup function in contrib/admin/static/admin/j

CVE-2026-93456 HIGH POC
8.4 Sep 18

Forged content modification in django-page-cms through 2.0.13 lets unauthenticated remote attackers exploit five CSRF-ex

CVE-2026-61593 HIGH POC
8.1 Sep 16

Cross-site request forgery in djust's Server-Sent-Events transport affects all versions prior to 1.0.7 and allows a cros

CVE-2026-61590 HIGH POC
7.4 Sep 16

Unauthenticated remote attackers can read live Django view and session state and invoke server-side handlers through dju

Vendor StatusVendor

Ubuntu

Priority: Medium
python-django
Release Status Version
upstream released 4.2.25,5.1.13,5.2.7
bionic released 1:1.11.11-1ubuntu1.21+esm12
focal released 2:2.2.12-1ubuntu0.29+esm4
jammy released 2:3.2.12-2ubuntu1.22
noble released 3:4.2.11-1ubuntu1.11
plucky released 3:4.2.18-1ubuntu1.5
trusty released 1.6.11-0ubuntu1.3+esm8
xenial released 1.8.7-1ubuntu5.15+esm9
questing released 3:5.2.4-1ubuntu2

Debian

Bug #1116979
python-django
Release Status Fixed Version Urgency
bullseye fixed 2:2.2.28-1~deb11u9 -
bullseye (security) fixed 2:2.2.28-1~deb11u12 -
bookworm fixed 3:3.2.25-0+deb12u1 -
bookworm (security) fixed 3:3.2.25-0+deb12u2 -
trixie fixed 3:4.2.27-0+deb13u1 -
trixie (security) fixed 3:4.2.28-0+deb13u1 -
forky, sid fixed 3:4.2.29-1 -
(unstable) fixed 3:4.2.25-1 -

SUSE

Severity: High
Product Status
SUSE Linux Enterprise Module for Package Hub 15 SP6 Fixed
SUSE Linux Enterprise Module for Package Hub 15 SP7 Fixed
SUSE Package Hub 15 SP6 Fixed
openSUSE Leap 15.6 Fixed
openSUSE Leap 16.0 Fixed

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy