CVE-2025-59681: Django SQL injection in column aliases on MySQL and MariaDB

CVE-2025-59681 · Severity: high · CVSS 7.1 · Published 2025-10-01

Django, a popular web framework, is vulnerable to a security flaw that could allow an attacker to execute unauthorized database commands. This issue occurs when the application uses specific database functions to organize or summarize data on MySQL or MariaDB databases. If exploited, an attacker could potentially access or modify sensitive information stored in the database, leading to data breaches or unauthorized data manipulation.

Technologies: Django (PyPI). Vendors: PyPI.

Quick answers

Is CVE-2025-59681 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2025-59681 being exploited in the wild.
How severe is CVE-2025-59681?
High severity, with a CVSS score of 7.1, published 1 October 2025.
Which products and versions are affected?
Django (PyPI) ECOSYSTEM:introduced=4.2,fixed=4.2.25, ECOSYSTEM:introduced=4.2,fixed=4.2.25,introduced=5.1,fixed=5.1.13,introduced=5.2,fixed=5.2.7.
Is there a fix for CVE-2025-59681?
Yes. Django (PyPI): upgrade to 4.2.25, 5.2.7 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2025-59681 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2025-59681?
Check whether you run Django (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • Django (PyPI): upgrade to 4.2.25, 5.2.7 or later
    pip install "Django>=5.2.7"

Technical details

A SQL injection vulnerability exists in Django's QuerySet.annotate(), QuerySet.alias(), QuerySet.aggregate(), and QuerySet.extra() methods. The root cause is improper neutralization of special elements in column aliases when using dictionary expansion (**kwargs) on MySQL and MariaDB backends. An attacker with low privileges can exploit this over the network by providing a specially crafted dictionary to these methods, potentially leading to unauthorized data access or modification. The vulnerability is mitigated by high attack complexity as it requires specific application-level coding patterns. Patches are available in versions 4.2.25, 5.1.13, and 5.2.7.

Affected products

  • Django Software Foundation Django >= 4.2, < 4.2.25
  • Django Software Foundation Django >= 5.1, < 5.1.13
  • Django Software Foundation Django >= 5.2, < 5.2.7

Identifiers

  • CVE-2025-59681
  • GHSA-hpr9-3m2g-3j9p
  • PYSEC-2025-106

Timeline

  • 2025-10-01: disclosed
  • 2025-10-01: advisory
  • 2025-10-01: patched

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.