Technology News • • 5-8 minutes

Django4Shell: a Django form could write a file wherever the attacker pointed it

Diego Cortés
Diego Cortés
Full Stack Developer & SEO Specialist
Share:
Django4Shell: a Django form could write a file wherever the attacker pointed it
Image generated with AI

On December 2 Django shipped three releases and seven patches. The loudest one, Django4Shell, never saves a record: it writes a file to disk while the form is being validated.

What Shipped on December 2

Django 6.1.4, 6.0.11 and 5.2.20 landed the same day and cover the main, 6.1, 6.0 and 5.2 branches. That is seven issues: two high, one moderate and four low. Unsupported branches such as 4.2, 5.0 and 5.1 were not evaluated and may be affected too: there is no patch to install there, the decision is to migrate.

The Main Flaw: RasterField Writes Where You Tell It To

CVE-2026-124827. When you assign a raster definition, a dict or a JSON string, to a RasterField with a user-controlled name and a driver other than the in-memory one, GDAL writes the raster to whatever path it is given. Depending on the driver, that write ends in remote code execution. EHdr, which writes plain binary, ships in every standard GDAL build: apt, yum, Homebrew and conda.

The Write Happens During Validation, Not on Save

RasterField has no form field of its own: it falls back to CharField. That is why the admin, a ModelForm or a writable serializer accept it without anyone declaring it. Assigning the value fires GDAL during validation, before any INSERT, and a name containing ../ steps outside the media directory. Validation, which many teams treat as a boundary, is the write primitive here.

From a File Write to Code Execution

The classic target is sitecustomize.py in the worker's working directory: Python imports it at startup, before your code. A .pth in site-packages works too. The payload runs on the next runserver reload, the next gunicorn fork or any subprocess, under the web server user. It is the technique used against LiteLLM earlier this year.

Who Is Exposed and Who Is Not

Four things must line up: a version below 5.2.20, 6.0.11 or 6.1.4; django.contrib.gis with at least one RasterField; a GDAL build with a driver that writes to disk; and a form an attacker can reach. The real barrier is staff authentication. Geometry fields were not affected and RasterField only exists on PostGIS: without GeoDjango there is nothing to check.

The Other Six Patches

The bundle carries a flaw with no nickname that deserved more attention. CVE-2026-132092 is SQL injection in the range and in lookups when an alias or key transform contains percent signs: the CVE record scores it 9.8 and Django rates it high. Not every range query becomes injectable, but the specific shape that was injectable was enough to read other people's data. CVE-2026-115868 is XSS in truncatechars_html when the text sits exactly at the cut point and is rendered inside an attribute. CVE-2026-125673 poisons the cache through . and .. path segments, and already-cached responses are not invalidated automatically: clear caches after deploying. The four low ones are two admin changelist leaks and a buffer overflow in OGRGeometry.wkb for geometries over 4 GB.

The severity got misreported. Early headlines called it a critical RCE with a 9.0; the CVE record says 8.8 under CVSS 3.1 and 8.7 under CVSS 4.0, and Django's policy calls it high. Both the Django4Shell nickname and the "incomplete fix" framing come from the researcher who reported it, Mohammed Fathy, not from the security team. It is the third GeoDjango raster fix in four months, after CVE-2026-15307 in August and CVE-2026-87890 in October. None of the seven is in CISA's KEV catalog and there are no reports of active exploitation.

What to Do Today

Upgrading to the patched release on your branch is the only real fix. After that:

  • Search your models for RasterField and check which forms, serializers and admin registrations expose it.
  • Make sure the deploy clears the caches affected by CVE-2026-125673.
  • Review range and in usages with aliases containing %.
  • Never accept raster dicts or JSON without validation: the advisory says the fix limits server-side file writes, but SSRF is still possible with untrusted input.

Closing

The lesson is wider than Django: when the client supplies a filename or a path, form validation is not a security boundary. PHP has the same trap when a route is built from request data. Today's tutorial covers the other half: serving files whose path the server decides, with the visitor receiving only a signature that expires.

If you run a Laravel app in production, the production security checklist covers the rest of the list, and upgrading PHP without downtime is the mechanics for an urgent patch without dropping traffic.

Categories