Django4Shell (CVE-2026-124827): GeoDjango RasterField Flaw Lets Attackers Write Files and Possibly Run Code, Plus SQL Injection CVE-2026-132092 — Update to 6.1.4, 6.0.11 or 5.2.20

Django's 2 December security releases fix seven flaws, led by a high-severity GeoDjango raster file write that can lead to code execution (the third fix for this code path since August) and an SQL injection in the range and in lookups.
The Django project shipped security releases 6.1.4, 6.0.11 and 5.2.20 on 2 December 2026. They fix seven vulnerabilities. Two are rated high: CVE-2026-124827, a server-side file write in GeoDjango's RasterField that its finder calls "Django4Shell" because it can lead to remote code execution, and CVE-2026-132092, an SQL injection in the ORM's range and in lookups.
This is the third time in four months that Django has patched the GeoDjango raster code path. If your project uses django.contrib.gis with raster fields, treat this update as urgent. Everyone else should still pick it up in their next deployment for the SQL injection and cross-site scripting fixes.
What Happened
The new releases cover Django main, 6.1, 6.0 and 5.2, the supported series. The project says older, unsupported series such as 5.1, 5.0 and 4.2 were not evaluated and may also be affected.
The seven CVEs are:
- CVE-2026-124827 (high): server-side file write via
RasterFieldassignment, possibly leading to code execution. Reported by Mohammed Fathy. - CVE-2026-132092 (high): potential SQL injection in
rangeandinlookups. Reported by Cristian Panaro. - CVE-2026-115868 (moderate): potential cross-site scripting in the
truncatechars_htmltemplate filter andTruncator.chars()withhtml=True. - CVE-2026-125673 (low): potential cache poisoning via
.and..segments in request paths, affectingUpdateCacheMiddlewareandcache_page(). - CVE-2026-119642 (low): admin changelist information leak via the
pkalias on aOneToOneField. - CVE-2026-127929 (low): admin changelist information leak via reverse relations. Django credits OpenAI with the report and says the issue regressed in Django 5.0.3.
- CVE-2026-132809 (low): heap buffer overflow in
OGRGeometry.wkbfor geometries larger than 4 GB on 64-bit platforms.
Django rates severity under its own policy and publishes no CVSS scores. A CVSS score of 9.0 for CVE-2026-124827 has been reported. That score did not come from the Django project.
Technical Details: Django4Shell (CVE-2026-124827)
GeoDjango's RasterField stores raster data in PostGIS and uses the GDAL library to handle it. According to the advisory, if a raster data definition with a user-controlled name and a non-default GDAL driver was assigned to a RasterField, GDAL could write a file to a location the attacker chose. Depending on the driver, that can lead to code execution.
The bug was reachable by default. RasterField falls back to an ordinary CharField form field, so the Django admin, ModelForms and writable serializers would all accept a raster definition as text.
The researcher says a crafted JSON raster body lets the attacker control the target path, the file content and the file name. Their example writes a Python file such as sitecustomize.py into a directory on the worker's import path, which Python runs automatically the next time the process starts. They also say the write happens during assignment, so no database save is needed. They list the conditions for exposure:
django.contrib.giswith a model that has aRasterField(only implemented on PostGIS).- That field exposed through a
ModelFormor the default admin. - A GDAL build with a driver that can write files. The researcher names the EHdr driver, which ships in standard builds.
- A target path the Django process can write to, such as the project root.
The researcher says the main requirement is staff-level authentication, because the admin is the usual entry point. The Django advisory itself does not limit exposure to staff. Any public form or API serializer that accepts raster input would widen the attack surface.
A third attempt at the same code path
This flaw has a history:
- CVE-2026-15307 (4 August, high): spatial lookups passed
stranddictvalues toGDALRaster. Staff users with only view permission could use admin changelist filters to write files or send network requests. - CVE-2026-87890 (6 October, moderate): Django says this fix overlooked raw
bytes. A GDAL VRT document could still make the server issue network requests as the Django process user. - CVE-2026-124827 (2 December, high): the earlier protections did not cover the
RasterFieldassignment path.
Technical Details: SQL Injection (CVE-2026-132092)
The range and in lookups were injectable in queries that used aliases or key transforms containing percent signs (%). The __range case needed more than two right-hand-side values. The __in case needed a bilateral transform.
These are uncommon patterns, but the risk is real wherever application code builds aliases or JSON key paths from user input. The fix makes range require exactly two values. Percent signs in column aliases and key transforms have been deprecated since Django 6.0 and are due to be removed in 2028.
Who Is Affected
- GeoDjango projects with
RasterFieldon PostGIS: highest risk, especially where the field is editable in the admin, aModelFormor a REST serializer. - Any Django project on 6.1 before 6.1.4, 6.0 before 6.0.11 or 5.2 before 5.2.20: affected by the SQL injection if it uses dynamic aliases or key transforms, and by the template-filter cross-site scripting bug if it renders
truncatechars_htmloutput inside HTML attributes. - Sites using Django's per-view or site-wide caching: may have the cache-poisoning issue.
- Projects on 5.1, 5.0, 4.2 or older: no patches. Plan an upgrade.
The project has not said that any of these flaws is being exploited. However, the researcher has published a dedicated disclosure site, and the GeoDjango raster bugs are now well documented.
Patch Status
Fixes are in Django 6.1.4, 6.0.11 and 5.2.20, and on the main branch. After the update, RasterField defaults to editable=False. It raises GDALException when a dict or JSON string sets a non-default driver. Code that really needs another driver must wrap the definition in GDALRaster to mark it as trusted.
The advisory warns that the fix "only limits server-side file writes". Server-side request forgery is still possible if untrusted input is assigned to RasterField, so applications should validate that input themselves.
What To Do Now
Upgrade, then confirm the installed version:
pip install --upgrade "Django>=6.1.4,<6.2" # or 6.0.11 / 5.2.20 for older series
python -m django --version
Then:
- Find raster fields:
grep -rn "RasterField" --include=*.py .shows whether you are in the high-risk group. - Close the input path: don't accept raster definitions from users at all. If you must, validate them strictly and never pass user-supplied driver names or file paths.
- Hunt for planted files: look for unexpected
sitecustomize.py,usercustomize.pyor.pthfiles in your project root, virtualenv and site-packages, and for new files written by the web-server user:
find / -xdev \( -name "sitecustomize.py" -o -name "usercustomize.py" -o -name "*.pth" \) -newermt "2026-08-01" 2>/dev/null
- Lock down the filesystem: run Django workers as a user that cannot write to the code directory or site-packages, and use read-only container filesystems where you can.
- Limit egress: block outbound connections from application servers that don't need them. This limits the server-side request forgery the fix leaves open.
- Clear caches: Django says existing cached responses are not invalidated by the fix, so flush your cache backends after upgrading.
- Review admin access: trim staff accounts and require multi-factor authentication on
/admin/.
Why It Matters
Django runs a large share of Python web back ends, and GeoDjango is common in mapping, logistics, agriculture and government systems. This release also shows how hard it is to patch a risky code path completely. Three fixes in four months each closed one way to send untrusted data into GDAL and missed another. Teams that rely on GDAL's many file formats should treat every raster or geometry input as untrusted and keep the server's file and network permissions as narrow as possible.
