CVE-2025-13372: Django SQL Injection Vulnerability in FilteredRelation Column Aliases
Summary
CVE-2025-13372: Potential SQL injection in FilteredRelation column aliases on PostgreSQL. Affects django across 3 version ranges.
>= 4.2.0, < 4.2.27
>= 5.1.0, < 5.1.15
>= 5.2.0, < 5.2.9
Fixed in 4.2.27, 5.1.15 or 5.2.9, depending on the release line you run. How to fix ↓
Also tracked for
The same CVE-2025-13372 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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.
No signup required · Results in about 60 seconds
Background
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It provides a robust set of features for building web applications, including an ORM (Object-Relational Mapping) system that allows developers to interact with databases using Python code. This vulnerability affects specific versions of Django, particularly in the way it handles column aliases in PostgreSQL when using the FilteredRelation feature.
Vulnerability Detail
An issue was discovered in Django versions 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27. The vulnerability arises from the use of FilteredRelation, which is susceptible to SQL injection through crafted dictionary inputs. When a user passes a dictionary with dictionary expansion as **kwargs to QuerySet.annotate() or QuerySet.alias() on PostgreSQL, it can lead to unauthorized SQL commands being executed. This could potentially allow an attacker to manipulate database queries, leading to data leakage or corruption.
How To Fix
Fixed versions by release line
The minimum fixed version depends on the release line you run.
-
>= 4.2.0, < 4.2.274.2.27 -
>= 5.1.0, < 5.1.155.1.15 -
>= 5.2.0, < 5.2.95.2.9
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading is not immediately possible, consider avoiding the use of FilteredRelation with dynamic column aliases in your queries until the update can be applied. Review your code to ensure that any user input is sanitized and validated before being used in database queries.
Conclusion
The CVE-2025-13372 vulnerability in Django poses a significant risk due to potential SQL injection through the FilteredRelation feature. It is crucial for developers using affected versions to update to the latest patched versions to mitigate this risk. Regular monitoring and proactive vulnerability management are essential for maintaining application security.
See every vulnerability recorded for django →
FAQ
CVE-2025-13372 is a vulnerability in Django that allows for potential SQL injection through the FilteredRelation feature when using certain versions of the framework.
Django versions 5.2 before 5.2.9, 5.1 before 5.1.15, and 4.2 before 4.2.27 are affected. Earlier unsupported versions may also be vulnerable.
You can use Vulert, which monitors open-source vulnerabilities in your software. By uploading your manifest file like package-lock.json, you can check for vulnerabilities without needing to access the code.
If an immediate upgrade is not feasible, avoid using FilteredRelation with dynamic column aliases and ensure that all user inputs are properly sanitized.
More details can be found in the official Django security advisory or on vulnerability databases like CVE and GitHub.
Related vulnerabilities
Recent vulnerabilities recorded for django.