Automated Threat Modeling

Overview of Django CVE-2026-132092: SQL Injection via range and in Lookups, with Patch Analysis

A brief summary of CVE-2026-132092, a SQL injection flaw in the Django ORM range and in lookups that appears when aliases or key transforms contain percent signs. Covers the root cause, the fix in Django 6.1.4, 6.0.11 and 5.2.20, and affected versions.

CVE Analysis

7 min read

Gaurav Sarraf
Gaurav Sarraf

2026-12-02

Overview of Django CVE-2026-132092: SQL Injection via range and in Lookups, with Patch Analysis

Introduction

Under specific query conditions, the Django ORM could bind query parameters to the wrong SQL placeholders when building range and in lookups, which opens a path to SQL injection inside the framework's own query construction layer. Because the bug lives in the ORM rather than in any single application, every project on an affected release inherits it. The CVE record scores it 9.8 Critical under CVSS 3.1 and 9.3 Critical under CVSS 4.0, and Django rates it high severity.

This post is a brief summary of CVE-2026-132092 based on the Django advisory, the CVE record and the upstream fix commits.

Technical information

Severity and classification

  • Weakness: CWE 89, SQL Injection
  • CVSS 3.1: 9.8 Critical, vector AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
  • CVSS 4.0: 9.3 Critical
  • Django rating: high

The vector describes a network-reachable flaw with low attack complexity, no privileges and no user interaction required, and high impact to confidentiality, integrity and availability. It is severity metadata only. The CVE record does not include a working proof of concept or reproduction steps.

Root cause: placeholders and parameters falling out of step

The Django ORM builds SQL strings containing %s placeholders and sends the values separately as a parameter list. That model is only safe while the number of placeholders equals the number of parameters.

If a column alias or JSON key transform contains a percent sign, for example x%sy, it adds an extra %s to the SQL text. Any lookup in the same query that also produces too many or too few parameters can then shift the parameter binding. A regression test added with the fix states plainly that "unbalanced placeholders and parameters could lead to SQL injection."

Two lookups could reach that unbalanced state.

__range

Range.get_rhs_op() read only the first two right-hand-side values and silently ignored any others:

class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def get_rhs_op(self, connection, rhs): return "BETWEEN %s AND %s" % (rhs[0], rhs[1])

If a caller passed three or more values, only two placeholders were rendered into the SQL text, but every value was still appended to the parameter list. The result was surplus parameters, which the stray %s contributed by a percent-sign alias could absorb.

__in with a bilateral transform

batch_process_rhs() paired compiled SQL fragments with their parameters using Python's default zip():

sql, params = zip( *( self.resolve_expression_parameter(compiler, connection, sql, param) for sql, param in zip(*pre_processed) ) )

A bilateral transform can compile None into IS NULL, which carries no parameter, so the fragment and parameter sequences can end up with different lengths. Default zip() silently truncates to the shorter input, so the mismatch was never surfaced.

Attack flow

Based on the advisory and the regression tests, the vulnerable condition comes together as follows:

  1. A query includes a column alias or a key transform whose name contains a percent sign, such as x%sy. This places an additional %s in the generated SQL text.
  2. The same query uses either __range with more than two right-hand-side values, or __in over a bilateral transform where the value list includes None and the list is batched (the test forces max_in_list_size to 2).
  3. The lookup emits a parameter count that no longer matches its own placeholders, and the extra %s from the alias picks up a value that was meant for a different position.
  4. Because the database driver now binds values to unintended placeholders, the structure of the executed query no longer matches what the ORM intended, which is the SQL injection condition the fix addresses.

The available records do not identify a specific application endpoint or describe how untrusted input reaches these conditions in a particular deployment. Teams assessing exposure should look at where their code builds aliases or key transforms dynamically and where range or in lookups receive caller-controlled value lists.

Patch information

Django fixed the issue in Django 6.1.4, 6.0.11 and 5.2.20, released December 2, 2026. The upstream fix is commit 1eb6104c on main, titled "Fixed CVE-2026-132092 -- Prevented SQL injection via Range and In lookups." Sarah Boyce wrote it with Jacob Walls as coauthor, and Simon Charette reviewed it. The 5.2.x backport is 5a8963c9. The upstream patch check output also lists e0e78769 for 6.1.x and da230e17 for 6.0.x.

The code change

The fix touches only three lines in django/db/models/lookups.py, and each change turns a silent mismatch into an error.

In batch_process_rhs(), the inner zip() becomes strict:

sql, params = zip( *( self.resolve_expression_parameter(compiler, connection, sql, param) for sql, param in zip(*pre_processed, strict=True) ) )

In Range, the right-hand side is unpacked instead of indexed:

class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def get_rhs_op(self, connection, rhs): start, end = rhs return "BETWEEN %s AND %s" % (start, end)
  • start, end = rhs uses tuple unpacking, which raises ValueError unless there are exactly two values. The query now fails before any SQL is built. The release notes state: "The range lookup now requires exactly two right-hand side values."
  • zip(..., strict=True) (Python 3.10+) raises ValueError when the SQL fragments and parameter lists differ in length, so __in can no longer bind parameters to the wrong placeholders.

What the regression tests check

  • test_range_lookup_requires_exactly_two_values asserts that Article.objects.filter(headline__range=["a", "b", "c"]) raises ValueError when evaluated. On main, a second test does the same with an annotated alias named x%sy.
  • test_values_expression_alias_bilateral_transform_null registers a bilateral Lower transform and runs name__lower__in=[None, "this", "that"] with max_in_list_size forced to 2, combined with a values("data__missing") key transform. The test comment acknowledges this query should work, but it now raises ValueError because strict=True blocks the surplus parameter.

Django chose to fail closed. In practice, a small number of legitimate but unusual __in queries that combine bilateral transforms with None may now raise errors instead of returning rows, and any code passing more than two values to range will now fail loudly.

Aliases and key transforms can still contain percent signs after the patch. What it removes are the two ways those stray placeholders could be exploited. Per the release notes, percent signs in column aliases and key transforms were already deprecated in Django 6.0, with removal scheduled for "Django 2028". On main, the commit adds a test confirming that values("data__x%sy") raises a RemovedInDjango2028Warning, and it leaves a commented-out "x%sy" entry in the alias injection test list, to be enabled once such aliases are rejected outright. The 5.2.x backport carries the same lookups.py changes and core regression tests, but not the tests tied to the 6.0 deprecation.

Affected systems and versions

  • Django 6.1: versions before 6.1.4 are affected, fixed in 6.1.4
  • Django 6.0: versions before 6.0.11 are affected, fixed in 6.0.11
  • Django 5.2: versions before 5.2.20 are affected, fixed in 5.2.20
  • Unsupported series (such as 5.1.x, 5.0.x and 4.2.x): not evaluated by Django and may also be affected. The advisory lists no fixed releases for them.

The vulnerable configuration is a query that involves an alias or key transform containing a percent sign together with a range lookup receiving more than two values, or an in lookup over a bilateral transform whose values include None and are batched.

Django encourages all users to upgrade as soon as possible, and the sources reviewed describe no workaround other than upgrading.

Vendor security history

Django is maintained with support from the Django Software Foundation. Its security team handles private reports and security policy, and Django Fellows, Foundation-funded contractors, manage releases and help resolve security issues. The project keeps a public archive of security issues, which notes that versions outside security support may have been affected without appearing in the supported version lists. In this case Django shipped coordinated fixes across the 5.2, 6.0 and 6.1 branches with regression tests. Earlier in 2026 the security team wrote publicly that many reports are variants of known issue patterns, and that it weighs consistent handling against the disruption security releases cause for users and maintainers. Django credits Cristian Panaro with reporting this issue.

References

Detect & fix
what others miss

Works with
  • GitHub
  • GitLab
  • Bitbucket
  • Azure DevOps Services
  • Gerrit
  • CVS
  • Jira
  • Linear
  • Slack
  • Security Compass
Explore integrations
Security magnifying glass visualization