DjangoFramework / library · Djangoproject

CVE-2025-59681

CRITICAL · 9.8 CVSS v3.1 Published 2025-10-01
Fix available
A fix is available. Upgrade to 4.2.25 / 5.1.13 or later.
See remediation →
100/100
Remediation priority · Urgent
Remotely reachable No privileges Zero-click

Official description Straight from the sourceThe vendor's or NVD's own wording, published unedited. Authoritative, but often terse — it says what broke, rarely what to do.

NVD · unedited
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).

Technical summary Written by usOur analysis, written from the advisory, the CVSS vector and the affected-version data. It adds context the advisory leaves out, and never invents facts that are not in the source.

dbcve analysis · high confidence

SQL injection vulnerability in Django's QuerySet methods (annotate, alias, aggregate, extra) allows arbitrary SQL execution through column aliases when using dictionary expansion as **kwargs on MySQL/MariaDB. User-controlled dictionary keys can manipulate the alias parameter to inject malicious SQL.

MitigationUpgrade Django to version 4.2.25, 5.1.13, or 5.2.7 or later. Until upgraded, avoid passing user-supplied dictionaries directly to these QuerySet methods without input validation.

Verify against the referenced sources before acting — the references below are authoritative for this CVE, this summary is not.

Affected products & versions What the vendor confirmedThe version ranges the vendor confirmed as vulnerable. If your version sits inside a range here, treat yourself as exposed until you have upgraded.

NVD · CPE data
DjangoFramework / library
Affected:>= 4.2, < 4.2.25>= 5.1, < 5.1.13>= 5.2, < 5.2.7

CVSS breakdown How the score is builtThe industry scoring standard. It rates how the flaw is reached, what it takes to exploit, and what an attacker gains — the score is derived from those, not the other way round.

From the vector
Attack vector
Network
Complexity
Low
Privileges
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Am I affected? How to checkSteps we derive from the advisory and the affected-version data, so you can decide whether this CVE reaches your setup. They are a guide, not a scan — your own configuration is the authority.

dbcve checks

Work through these to decide whether this CVE applies to you.

  1. Identify installed Django version
    Run 'django-admin --version' or import django; print(django.get_version()) in Python
    Affected if The version is 4.2.x below 4.2.25, 5.1.x below 5.1.13, or 5.2.x below 5.2.7
  2. Confirm database backend in use
    Inspect settings.py DATABASES configuration, specifically the 'ENGINE' value (e.g., django.db.backends.mysql)
    Affected if The backend is MySQL (mysql) or MariaDB (mysql or mariadb)
  3. Search for vulnerable QuerySet method usage
    Grep source code for calls to .annotate(, .alias(, .aggregate(, or .extra( followed by ** and a variable name, e.g., '**request.GET' or '**user_dict'
    Affected if User-controlled input (request parameters, user variables) is unpacked as **kwargs into these methods
  4. Inspect dictionary expansion patterns
    Search for patterns like Model.objects.annotate(**user_dict) or Model.objects.aggregate(**kwargs) where kwargs could originate from HTTP request parameters or user input
    Affected if User-supplied dictionary keys are passed directly to annotate, alias, aggregate, or extra methods without validation

You are affected if you run a vulnerable Django version (4.2.x < 4.2.25, 5.1.x < 5.1.13, or 5.2.x < 5.2.7) AND use MySQL/MariaDB AND pass user-controlled dictionaries to annotate, alias, aggregate, or extra methods via **kwargs expansion.

Generated from the published advisory. Verify against your own configuration.

Check your environment

Paste your version and any relevant configuration and it will be compared against the affected criteria above. Do not include secrets or credentials.

AI-assisted, checked against the advisory. Informational, not a guarantee.

Remediation Closing itWhat it takes to close this. Where a vendor fix exists we point at it; where none exists we say so plainly, and can build one. Effort estimates are scoped from the advisory, not from your codebase.

dbcve · scoped
Upgrade available Upgrade to 4.2.25 / 5.1.13 / 5.2.7 or later
Fixed in 4.2.255.1.135.2.7
Interim mitigation

Upgrade Django to version 4.2.25, 5.1.13, or 5.2.7 or later. Until upgraded, avoid passing user-supplied dictionaries directly to these QuerySet methods without input validation.

Recommended fix High confidence

Django 4.2.25 (for 4.2.x), Django 5.1.13 (for 5.1.x), or Django 5.2.7 (for 5.2.x)

  1. Identify the currently installed Django version using 'pip show django' or 'django-admin --version'
  2. For Django 4.2.x: Upgrade to 4.2.25 by running 'pip install django>=4.2.25,<5.0' or 'pip install django==4.2.25'
  3. For Django 5.1.x: Upgrade to 5.1.13 by running 'pip install django>=5.1.13,<5.2' or 'pip install django==5.1.13'
  4. For Django 5.2.x: Upgrade to 5.2.7 by running 'pip install django>=5.2.7,<6.0' or 'pip install django==5.2.7'
  5. After upgrading, run tests to verify application functionality
  6. Ensure the application works correctly with MySQL or MariaDB databases, as this vulnerability specifically affects those database backends
Caveat Review Django 4.2.25, 5.1.13, and 5.2.7 release notes for any breaking changes between your current version and the target version before upgrading

Generated from the published advisory — verify against the referenced sources before acting.

Fix this in Django Scoped from the published advisory
  • Consultation8.0 h
  • Implementation4.0 h
  • Testing6.0 h
  • Review / QA4.0 h
22.0 hours of engineering $3,940
Get the upgrade done

An estimate, not a bill — we confirm scope with you before any work starts. Need it this week? Rush from $6,304.

Scan for this in your stack

Free · runs locally
dbcve dependency scanner

Check whether your project pulls in CVE-2025-59681 — or any other known-vulnerable package — straight from your lock files. Free and open source; it runs locally and uploads nothing.

References Go to the primary sourcePrimary sources — vendor advisories, patches and trackers. Where our summary and a reference disagree, the reference wins.

Primary sources

Practitioner notes

Contributed

Peer-ranked notes from engineers who’ve handled CVE-2025-59681 in production — separate from our analysis above.

No notes yet

Be the first to add a field note for this CVE — a mitigation you’ve verified, a version caveat, or a link to a working fix. Sign in above to contribute.

What this is

A place for practitioners to share what actually worked: a mitigation you’ve tested, a configuration change, a version- or environment-specific caveat, or a link to a verified patch. The most useful notes rise to the top as peers upvote them, so the signal stays high.

What belongs here
  • Verified mitigations, workarounds, and config changes
  • Version or environment caveats, and links to real fixes
  • No weaponised exploit code, or anything meant to cause harm
  • No spam, self-promotion, credentials, or personal data