CVE-2025-57833: 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.24, 5.1 before 5.1.12, and 5.2 before 5.2.6. FilteredRelation is subject to SQL injection in column aliases, using a suitably crafted dictionary, with dictionary expansion, as the **kwargs passed QuerySet.annotate() or QuerySet.alias().
AI Analysis
Technical Summary
CVE-2025-57833 is a SQL injection vulnerability identified in the Django web framework, specifically affecting versions 4.2 before 4.2.24, 5.1 before 5.1.12, and 5.2 before 5.2.6. The vulnerability arises from improper neutralization of special elements in SQL commands (CWE-89) within the FilteredRelation feature. This feature allows developers to create complex queries by annotating or aliasing QuerySets with dynamically constructed dictionaries expanded as **kwargs. When these dictionaries are crafted maliciously, they can inject SQL code into column aliases, which are not properly sanitized before being incorporated into the underlying SQL query. The vulnerability requires an attacker to have network access and low privileges within the application but does not require user interaction. The CVSS v3.1 score is 7.1 (high severity), reflecting a network attack vector, high complexity, low privileges required, no user interaction, and a scope change. The impact primarily affects confidentiality, potentially exposing sensitive database information, with limited impact on integrity and no impact on availability. No public exploits have been reported yet, but the vulnerability poses a significant risk given Django's widespread use in web applications. The flaw is particularly dangerous because it can be triggered via dictionary expansion in QuerySet.annotate() or QuerySet.alias(), which are common ORM features used to build dynamic queries. Developers relying on these features without proper input validation or patching are vulnerable. The issue was reserved on 2025-08-20 and published on 2025-09-03, with patches available in the specified Django versions.
Potential Impact
For European organizations, this vulnerability can lead to unauthorized disclosure of sensitive data stored in backend databases, including personal data protected under GDPR. The confidentiality breach can result in regulatory penalties, reputational damage, and loss of customer trust. Since Django is widely used in sectors such as finance, healthcare, government, and e-commerce across Europe, the risk is substantial. Attackers exploiting this vulnerability could extract confidential information without needing elevated privileges or user interaction, increasing the attack surface. Although integrity impact is limited, attackers might leverage the information gained to plan further attacks. The absence of availability impact means systems remain operational, potentially allowing prolonged data exfiltration. Organizations that have not updated Django or audited their use of FilteredRelation with dynamic annotations are at heightened risk. The vulnerability also poses a threat to supply chain security, as compromised Django-based applications could propagate risks downstream.
Mitigation Recommendations
European organizations should immediately upgrade Django to versions 4.2.24, 5.1.12, or 5.2.6 or later, where the vulnerability is patched. Conduct a thorough code review focusing on the use of QuerySet.annotate() and QuerySet.alias() with dictionary expansions, especially involving FilteredRelation, to identify unsafe dynamic SQL constructions. Implement strict input validation and sanitization for any user-controllable data used in query annotations or aliases. Employ Web Application Firewalls (WAFs) with custom rules to detect and block suspicious SQL injection patterns targeting Django ORM queries. Monitor application logs for anomalous query patterns or unexpected database errors that could indicate exploitation attempts. Enforce the principle of least privilege on database accounts used by Django applications to limit data exposure in case of compromise. Additionally, integrate runtime application self-protection (RASP) tools to detect and prevent injection attacks in real time. Finally, ensure incident response plans include procedures for SQL injection incidents and data breach notifications compliant with GDPR.
Affected Countries
Germany, United Kingdom, France, Netherlands, Sweden, Italy, Spain
CVE-2025-57833: 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.24, 5.1 before 5.1.12, and 5.2 before 5.2.6. FilteredRelation is subject to SQL injection in column aliases, using a suitably crafted dictionary, with dictionary expansion, as the **kwargs passed QuerySet.annotate() or QuerySet.alias().
AI-Powered Analysis
Technical Analysis
CVE-2025-57833 is a SQL injection vulnerability identified in the Django web framework, specifically affecting versions 4.2 before 4.2.24, 5.1 before 5.1.12, and 5.2 before 5.2.6. The vulnerability arises from improper neutralization of special elements in SQL commands (CWE-89) within the FilteredRelation feature. This feature allows developers to create complex queries by annotating or aliasing QuerySets with dynamically constructed dictionaries expanded as **kwargs. When these dictionaries are crafted maliciously, they can inject SQL code into column aliases, which are not properly sanitized before being incorporated into the underlying SQL query. The vulnerability requires an attacker to have network access and low privileges within the application but does not require user interaction. The CVSS v3.1 score is 7.1 (high severity), reflecting a network attack vector, high complexity, low privileges required, no user interaction, and a scope change. The impact primarily affects confidentiality, potentially exposing sensitive database information, with limited impact on integrity and no impact on availability. No public exploits have been reported yet, but the vulnerability poses a significant risk given Django's widespread use in web applications. The flaw is particularly dangerous because it can be triggered via dictionary expansion in QuerySet.annotate() or QuerySet.alias(), which are common ORM features used to build dynamic queries. Developers relying on these features without proper input validation or patching are vulnerable. The issue was reserved on 2025-08-20 and published on 2025-09-03, with patches available in the specified Django versions.
Potential Impact
For European organizations, this vulnerability can lead to unauthorized disclosure of sensitive data stored in backend databases, including personal data protected under GDPR. The confidentiality breach can result in regulatory penalties, reputational damage, and loss of customer trust. Since Django is widely used in sectors such as finance, healthcare, government, and e-commerce across Europe, the risk is substantial. Attackers exploiting this vulnerability could extract confidential information without needing elevated privileges or user interaction, increasing the attack surface. Although integrity impact is limited, attackers might leverage the information gained to plan further attacks. The absence of availability impact means systems remain operational, potentially allowing prolonged data exfiltration. Organizations that have not updated Django or audited their use of FilteredRelation with dynamic annotations are at heightened risk. The vulnerability also poses a threat to supply chain security, as compromised Django-based applications could propagate risks downstream.
Mitigation Recommendations
European organizations should immediately upgrade Django to versions 4.2.24, 5.1.12, or 5.2.6 or later, where the vulnerability is patched. Conduct a thorough code review focusing on the use of QuerySet.annotate() and QuerySet.alias() with dictionary expansions, especially involving FilteredRelation, to identify unsafe dynamic SQL constructions. Implement strict input validation and sanitization for any user-controllable data used in query annotations or aliases. Employ Web Application Firewalls (WAFs) with custom rules to detect and block suspicious SQL injection patterns targeting Django ORM queries. Monitor application logs for anomalous query patterns or unexpected database errors that could indicate exploitation attempts. Enforce the principle of least privilege on database accounts used by Django applications to limit data exposure in case of compromise. Additionally, integrate runtime application self-protection (RASP) tools to detect and prevent injection attacks in real time. Finally, ensure incident response plans include procedures for SQL injection incidents and data breach notifications compliant with GDPR.
Affected Countries
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-08-20T00:00:00.000Z
- Cvss Version
- 3.1
- State
- PUBLISHED
Threat ID: 68b8a5f1ad5a09ad00fa3013
Added to database: 9/3/2025, 8:32:49 PM
Last enriched: 11/10/2025, 9:25:08 PM
Last updated: 12/4/2025, 7:54:22 PM
Views: 145
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-29269: n/a
UnknownCVE-2025-29268: n/a
UnknownCVE-2025-65883: n/a
UnknownCVE-2025-65806: n/a
UnknownCVE-2025-12097: CWE-23- Relative Path Traversal in NI LabVIEW
HighActions
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.