CVE-2025-13372: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in djangoproject Django
An issue was discovered in 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27. `FilteredRelation` is subject to SQL injection in column aliases, using a suitably crafted dictionary, with dictionary expansion, as the `**kwargs` passed to `QuerySet.annotate()` or `QuerySet.alias()` on PostgreSQL. Earlier, unsupported Django series (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated and may also be affected. Django would like to thank Stackered for reporting this issue.
AI Analysis
Technical Summary
CVE-2025-13372 is a SQL injection vulnerability identified in the Django web framework, specifically affecting versions 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27. The vulnerability stems from the FilteredRelation feature, which is used to create filtered joins in Django ORM queries. When developers use dictionary expansion (**kwargs) to pass parameters to QuerySet.annotate() or QuerySet.alias(), the column aliases generated can be manipulated with specially crafted dictionaries. This improper neutralization of special elements in SQL commands (CWE-89) allows an attacker to inject arbitrary SQL code into the query executed on PostgreSQL databases. The issue is specific to PostgreSQL due to how column aliases are handled in this database backend. Earlier unsupported Django versions (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated but may also be vulnerable. Exploitation requires user interaction (e.g., submitting crafted input) but does not require authentication, increasing the attack surface. The CVSS v3.1 base score is 4.3 (medium), reflecting a network attack vector with low complexity and no privileges required, but user interaction is necessary. The impact is limited to confidentiality, with no direct integrity or availability consequences. No public exploits have been reported yet, but the vulnerability was responsibly disclosed by the security researcher Stackered. Django maintainers have released patches in the specified versions to address this issue.
Potential Impact
The primary impact of CVE-2025-13372 is unauthorized disclosure of sensitive information due to SQL injection in Django applications using vulnerable versions with PostgreSQL backends. Attackers exploiting this vulnerability can potentially extract data from the database by manipulating SQL queries via the FilteredRelation feature. Although the vulnerability does not directly affect data integrity or system availability, the confidentiality breach can lead to exposure of sensitive user data, intellectual property, or configuration details. Organizations relying on Django for web applications, especially those handling sensitive or regulated data, face increased risk of data leakage. Since no authentication is required, and the attack vector is network-based with user interaction, public-facing web applications are particularly at risk. The absence of known exploits in the wild reduces immediate threat but does not eliminate the risk of future exploitation. The vulnerability could be leveraged as part of a larger attack chain to gain further access or escalate privileges if combined with other weaknesses.
Mitigation Recommendations
To mitigate CVE-2025-13372, organizations should immediately upgrade Django to versions 5.2.9 or later, 5.1.15 or later, or 4.2.27 or later where the vulnerability is patched. If upgrading is not immediately feasible, developers should avoid using dictionary expansion (**kwargs) with QuerySet.annotate() or QuerySet.alias() when working with FilteredRelation on PostgreSQL. Implement strict input validation and sanitization on any user-supplied data that could influence ORM query parameters. Employ Web Application Firewalls (WAFs) with rules targeting SQL injection patterns specific to Django ORM queries. Conduct thorough code reviews focusing on ORM query construction to detect unsafe usage patterns. Monitor application logs for unusual query patterns or errors indicative of attempted injection. Additionally, restrict database user permissions to the minimum necessary to limit data exposure in case of exploitation. Finally, maintain an incident response plan to quickly address any detected exploitation attempts.
Affected Countries
United States, United Kingdom, Germany, France, Japan, Australia, Canada, Netherlands, India, Brazil
CVE-2025-13372: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in djangoproject Django
Description
An issue was discovered in 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27. `FilteredRelation` is subject to SQL injection in column aliases, using a suitably crafted dictionary, with dictionary expansion, as the `**kwargs` passed to `QuerySet.annotate()` or `QuerySet.alias()` on PostgreSQL. Earlier, unsupported Django series (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated and may also be affected. Django would like to thank Stackered for reporting this issue.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
CVE-2025-13372 is a SQL injection vulnerability identified in the Django web framework, specifically affecting versions 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27. The vulnerability stems from the FilteredRelation feature, which is used to create filtered joins in Django ORM queries. When developers use dictionary expansion (**kwargs) to pass parameters to QuerySet.annotate() or QuerySet.alias(), the column aliases generated can be manipulated with specially crafted dictionaries. This improper neutralization of special elements in SQL commands (CWE-89) allows an attacker to inject arbitrary SQL code into the query executed on PostgreSQL databases. The issue is specific to PostgreSQL due to how column aliases are handled in this database backend. Earlier unsupported Django versions (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated but may also be vulnerable. Exploitation requires user interaction (e.g., submitting crafted input) but does not require authentication, increasing the attack surface. The CVSS v3.1 base score is 4.3 (medium), reflecting a network attack vector with low complexity and no privileges required, but user interaction is necessary. The impact is limited to confidentiality, with no direct integrity or availability consequences. No public exploits have been reported yet, but the vulnerability was responsibly disclosed by the security researcher Stackered. Django maintainers have released patches in the specified versions to address this issue.
Potential Impact
The primary impact of CVE-2025-13372 is unauthorized disclosure of sensitive information due to SQL injection in Django applications using vulnerable versions with PostgreSQL backends. Attackers exploiting this vulnerability can potentially extract data from the database by manipulating SQL queries via the FilteredRelation feature. Although the vulnerability does not directly affect data integrity or system availability, the confidentiality breach can lead to exposure of sensitive user data, intellectual property, or configuration details. Organizations relying on Django for web applications, especially those handling sensitive or regulated data, face increased risk of data leakage. Since no authentication is required, and the attack vector is network-based with user interaction, public-facing web applications are particularly at risk. The absence of known exploits in the wild reduces immediate threat but does not eliminate the risk of future exploitation. The vulnerability could be leveraged as part of a larger attack chain to gain further access or escalate privileges if combined with other weaknesses.
Mitigation Recommendations
To mitigate CVE-2025-13372, organizations should immediately upgrade Django to versions 5.2.9 or later, 5.1.15 or later, or 4.2.27 or later where the vulnerability is patched. If upgrading is not immediately feasible, developers should avoid using dictionary expansion (**kwargs) with QuerySet.annotate() or QuerySet.alias() when working with FilteredRelation on PostgreSQL. Implement strict input validation and sanitization on any user-supplied data that could influence ORM query parameters. Employ Web Application Firewalls (WAFs) with rules targeting SQL injection patterns specific to Django ORM queries. Conduct thorough code reviews focusing on ORM query construction to detect unsafe usage patterns. Monitor application logs for unusual query patterns or errors indicative of attempted injection. Additionally, restrict database user permissions to the minimum necessary to limit data exposure in case of exploitation. Finally, maintain an incident response plan to quickly address any detected exploitation attempts.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- DSF
- Date Reserved
- 2025-11-18T18:34:58.688Z
- Cvss Version
- null
- State
- PUBLISHED
Threat ID: 692f093f16d939a309c3099b
Added to database: 12/2/2025, 3:43:59 PM
Last enriched: 2/27/2026, 9:45:42 AM
Last updated: 3/22/2026, 2:04:52 AM
Views: 411
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.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.