On 2 December 2026, the Django team released Django 6.1.4, 6.0.11 and 5.2.20. Together they fix seven security issues. Two are rated high: an SQL injection in the range and in lookups, and a server-side file write through GeoDjango’s RasterField. The rest cover an XSS edge case, cache poisoning, two admin information leaks and a GDAL buffer overflow.

The official announcement asks everyone to upgrade as soon as possible. This guide explains each fix in plain English, shows who is affected, and covers the code changes some projects need after upgrading.

Which version should you install?

You run Upgrade to
Django 6.1.x 6.1.4
Django 6.0.x 6.0.11
Django 5.2.x (LTS) 5.2.20

The affected supported versions are main, 6.1, 6.0 and 5.2. If you’re on an unsupported series, these patches won’t reach you. Treat this as a reason to move to 5.2 LTS or newer.

pip install --upgrade "django==6.1.4"     # or 6.0.11 / 5.2.20
python -m django --version
python manage.py check --deploy

Using uv:

uv add "django==6.1.4"
uv lock --upgrade-package django

The two high-severity fixes

CVE-2026-132092: SQL injection in range and in lookups

The range and in lookups could be used for SQL injection in queries with aliases or key transforms that contain percent signs. The announcement explains the conditions. For __range, the flaw also required incorrectly passing more than two right-hand values. For __in, it needed a bilateral transform.

The fix makes range require exactly two values. Code that used to pass a longer list now fails instead of building a dangerous query. We checked this with Django 6.1.4 and the built-in User model:

User.objects.filter(id__range=(1, 5))      # fine: BETWEEN 1 AND 5
User.objects.filter(id__range=[1, 5, 9])   # now raises
# ValueError: too many values to unpack (expected 2)

What to do: search your code for __range= and make sure every call passes exactly a start and an end. Pay most attention where the bounds come from request data:

grep -rn "__range" --include="*.py" .

A safe pattern for user input:

from datetime import date

def orders_between(request):
    try:
        start = date.fromisoformat(request.GET["from"])
        end = date.fromisoformat(request.GET["to"])
    except (KeyError, ValueError):
        return HttpResponseBadRequest("from/to must be ISO dates")
    return Order.objects.filter(created__date__range=(start, end))

The announcement also reminds you that percent signs in column aliases and key transforms were already deprecated in Django 6.0. If you build aliases from user input, stop now, whatever version you’re on.

CVE-2026-124827: file write via RasterField

This only affects GeoDjango on PostGIS projects that use RasterField. If a user could assign a raster data definition with a chosen name and a non-default driver, GDAL could write a file anywhere the attacker picked. Depending on the driver, that could lead to remote code execution. RasterField falls back to a CharField form field, so the flaw was reachable by default through the admin, ModelForms and writable serializers.

The fix makes two changes:

  • RasterField now defaults to editable=False, so ModelForms leave it out unless you include it explicitly.
  • Assigning a dict or JSON string that names a non-default driver now raises GDALException. If you trust the value, wrap it in GDALRaster to say so.
from django.contrib.gis.gdal import GDALRaster

# Trusted, server-side definition only:
tile.raster = GDALRaster({"driver": "GTiff", "name": "/srv/tiles/t1.tif", ...})

The Django team warns that this fix only blocks file writes. Server-side request forgery is still possible if you assign untrusted input to RasterField. Validate it first, as the GDAL security considerations describe.

The moderate and low-severity fixes

CVE-2026-115868: XSS in truncatechars_html (moderate)

The truncatechars_html filter and Truncator.chars(..., html=True) could produce an XSS issue. This happened when the input’s text length matched the truncation length exactly and the result was rendered inside an HTML attribute. Upgrading fixes it. It’s still worth checking templates that put truncated HTML into attributes, such as title="{{ post.body|truncatechars_html:80 }}". In attributes, plain truncatechars on text you’ve already escaped is usually the better choice.

CVE-2026-125673: cache poisoning through dot segments (low)

UpdateCacheMiddleware and cache_page() relied on HttpRequest.build_absolute_uri(), which wrongly normalised paths containing . or ... With some URL and deployment setups, an unauthenticated attacker could get a cached response served for the wrong URL. build_absolute_uri() now keeps dot segments when called without a location.

Important: upgrading doesn’t remove responses that are already cached. The Django team says you should clear any potentially affected caches after upgrading:

# python manage.py shell
from django.core.cache import caches
caches["default"].clear()   # repeat for any cache alias used by cache_page

CVE-2026-119642 and CVE-2026-127929: admin changelist leaks (low)

These are two variants of an old problem (CVE-2010-4534). Staff users with only view permission could build querystrings and repeat lookup searches to work out values they shouldn’t see. One variant used the pk alias on models whose primary key is a custom OneToOneField. That includes every model using multi-table inheritance. The other used reverse relations and had come back as a regression in Django 5.0.3. Both need a logged-in staff account, but if you give contractors or support staff view-only admin access, upgrade quickly.

CVE-2026-132809: heap overflow in OGRGeometry.wkb (low)

OGRGeometry.wkb allocated a buffer that was too small for geometries over 4GB on 64-bit platforms, which could cause crashes. The hex and geos properties and pickling were also affected. Few apps handle geometries that large, but the fix comes with the same upgrade.

Post-upgrade checklist

  1. Upgrade to 6.1.4, 6.0.11 or 5.2.20 and redeploy every service that imports Django, including Celery workers.
  2. Search for __range and make sure each call passes exactly two values.
  3. If you use GeoDjango rasters, add RasterField explicitly to any form that should edit it, and wrap trusted definitions in GDALRaster.
  4. Clear caches used by cache_page or the cache middleware.
  5. Check templates that use truncatechars_html inside attributes.
  6. Run your test suite and python manage.py check --deploy.

Takeaway

This is a “patch today” release. For most apps the upgrade is a drop-in, but there are three changes to watch for: __range now insists on exactly two values, RasterField is no longer editable by default, and cached pages may need clearing. Read the full security announcement and the 6.1.4 release notes for links to the commits.