CVE-2025-59681: CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in djangoproject Django
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).
AI Analysis
Technical Summary
CVE-2025-59681 is a SQL injection vulnerability classified under CWE-89, discovered in Django web framework versions 4.2 (before 4.2.25), 5.1 (before 5.1.13), and 5.2 (before 5.2.7). The vulnerability arises in the QuerySet methods annotate(), alias(), aggregate(), and extra() when these methods receive keyword arguments via dictionary expansion (**kwargs) that define column aliases. Specifically, when these kwargs are crafted maliciously and used on MySQL or MariaDB backends, the input is not properly neutralized, allowing injection of arbitrary SQL commands. This improper sanitization can lead to execution of unintended SQL statements, potentially exposing or altering sensitive data. The vulnerability requires low privileges (PR:L) but has a high attack complexity (AC:H), meaning the attacker must carefully craft the input and conditions to exploit it. No user interaction is needed (UI:N), and the scope is changed (S:C) because the vulnerability can affect resources beyond the initially vulnerable component. The CVSS v3.1 base score is 7.1, indicating high severity, with impact primarily on confidentiality (C:H) and some integrity (I:L), but no impact on availability (A:N). There are no known exploits in the wild as of the publication date, and no official patches linked in the provided data, but it is expected that patched versions are available or forthcoming. This vulnerability is critical for applications using Django with MySQL or MariaDB databases, especially where user input is passed unsafely to these QuerySet methods.
Potential Impact
For European organizations, this vulnerability poses a significant risk to web applications built on Django versions 4.2, 5.1, and 5.2 that use MySQL or MariaDB as their database backend. Exploitation can lead to unauthorized disclosure of sensitive data, such as personal information or intellectual property, violating GDPR and other data protection regulations. The integrity of data can also be compromised, potentially affecting business operations and trustworthiness of information. Given the widespread use of Django in sectors like finance, healthcare, and government services across Europe, successful exploitation could disrupt critical services or lead to regulatory penalties. The high attack complexity somewhat limits mass exploitation but targeted attacks against high-value assets remain a concern. Organizations relying on these Django versions without timely patching or code review are vulnerable to data breaches and reputational damage.
Mitigation Recommendations
European organizations should immediately audit their Django applications to identify usage of QuerySet methods annotate(), alias(), aggregate(), and extra() where dictionary expansion (**kwargs) is used, especially on MySQL or MariaDB backends. The primary mitigation is to upgrade Django to versions 4.2.25 or later, 5.1.13 or later, and 5.2.7 or later once patches are available. Until upgrades can be applied, developers should avoid passing untrusted input via dictionary expansion to these QuerySet methods or implement strict input validation and sanitization. Employing Web Application Firewalls (WAFs) with custom rules to detect suspicious SQL patterns may provide temporary protection. Additionally, monitoring database query logs for anomalous queries can help detect exploitation attempts. Organizations should also review database user permissions to follow the principle of least privilege, limiting the potential impact of any injection. Regular security testing, including code reviews and penetration testing focused on ORM usage, is recommended to prevent similar vulnerabilities.
Affected Countries
Germany, France, United Kingdom, Netherlands, Sweden, Italy, Spain, Poland, Belgium, Finland
CVE-2025-59681: CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in djangoproject Django
Description
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).
AI-Powered Analysis
Technical Analysis
CVE-2025-59681 is a SQL injection vulnerability classified under CWE-89, discovered in Django web framework versions 4.2 (before 4.2.25), 5.1 (before 5.1.13), and 5.2 (before 5.2.7). The vulnerability arises in the QuerySet methods annotate(), alias(), aggregate(), and extra() when these methods receive keyword arguments via dictionary expansion (**kwargs) that define column aliases. Specifically, when these kwargs are crafted maliciously and used on MySQL or MariaDB backends, the input is not properly neutralized, allowing injection of arbitrary SQL commands. This improper sanitization can lead to execution of unintended SQL statements, potentially exposing or altering sensitive data. The vulnerability requires low privileges (PR:L) but has a high attack complexity (AC:H), meaning the attacker must carefully craft the input and conditions to exploit it. No user interaction is needed (UI:N), and the scope is changed (S:C) because the vulnerability can affect resources beyond the initially vulnerable component. The CVSS v3.1 base score is 7.1, indicating high severity, with impact primarily on confidentiality (C:H) and some integrity (I:L), but no impact on availability (A:N). There are no known exploits in the wild as of the publication date, and no official patches linked in the provided data, but it is expected that patched versions are available or forthcoming. This vulnerability is critical for applications using Django with MySQL or MariaDB databases, especially where user input is passed unsafely to these QuerySet methods.
Potential Impact
For European organizations, this vulnerability poses a significant risk to web applications built on Django versions 4.2, 5.1, and 5.2 that use MySQL or MariaDB as their database backend. Exploitation can lead to unauthorized disclosure of sensitive data, such as personal information or intellectual property, violating GDPR and other data protection regulations. The integrity of data can also be compromised, potentially affecting business operations and trustworthiness of information. Given the widespread use of Django in sectors like finance, healthcare, and government services across Europe, successful exploitation could disrupt critical services or lead to regulatory penalties. The high attack complexity somewhat limits mass exploitation but targeted attacks against high-value assets remain a concern. Organizations relying on these Django versions without timely patching or code review are vulnerable to data breaches and reputational damage.
Mitigation Recommendations
European organizations should immediately audit their Django applications to identify usage of QuerySet methods annotate(), alias(), aggregate(), and extra() where dictionary expansion (**kwargs) is used, especially on MySQL or MariaDB backends. The primary mitigation is to upgrade Django to versions 4.2.25 or later, 5.1.13 or later, and 5.2.7 or later once patches are available. Until upgrades can be applied, developers should avoid passing untrusted input via dictionary expansion to these QuerySet methods or implement strict input validation and sanitization. Employing Web Application Firewalls (WAFs) with custom rules to detect suspicious SQL patterns may provide temporary protection. Additionally, monitoring database query logs for anomalous queries can help detect exploitation attempts. Organizations should also review database user permissions to follow the principle of least privilege, limiting the potential impact of any injection. Regular security testing, including code reviews and penetration testing focused on ORM usage, is recommended to prevent similar vulnerabilities.
For access to advanced analysis and higher rate limits, contact root@offseq.com
Technical Details
- Data Version
- 5.1
- Assigner Short Name
- mitre
- Date Reserved
- 2025-09-18T00:00:00.000Z
- Cvss Version
- 3.1
- State
- PUBLISHED
Threat ID: 68dd78861b22ab5635985422
Added to database: 10/1/2025, 6:52:54 PM
Last enriched: 11/4/2025, 10:13:35 PM
Last updated: 11/17/2025, 2:42:11 AM
Views: 214
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Related Threats
CVE-2025-13258: Buffer Overflow in Tenda AC20
HighCVE-2025-13257: SQL Injection in itsourcecode Inventory Management System
MediumCVE-2025-13256: SQL Injection in projectworlds Advanced Library Management System
MediumCVE-2025-13255: SQL Injection in projectworlds Advanced Library Management System
MediumCVE-2025-13254: SQL Injection in projectworlds Advanced Library Management System
MediumActions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need enhanced features?
Contact root@offseq.com for Pro access with improved analysis and higher rate limits.