Django4Shell: Remote Code Execution via GeoDjango’s RasterField

On 2 December 2026, the Django project released security versions 6.1.4, 6.0.11 and 5.2.20. Among other fixes, they address CVE-2026-124827, named “Django4Shell” by the researcher who found it. The flaw affects GeoDjango’s RasterField: a raster definition submitted through a form can make the GDAL library write a file to a location chosen by the attacker. Depending on the GDAL driver, this can lead to remote code execution. Our Audit & Offensive Security team reproduced the full chain in an isolated environment.

Key points
  • RasterField falls back to a CharField form field, so it was editable by default in the Django admin, in ModelForms and in writable model serializers.
  • A raster definition (dict or JSON) with a user-controlled name and a non-default GDAL driver can write a file to an arbitrary location on the server.
  • Depending on the driver, this write leads to code execution, for example by dropping a .pth or sitecustomize.py file that runs the next time Python starts.
  • Only GeoDjango applications on PostGIS that expose a RasterField are affected. Geometry fields are not.
  • Fix: RasterField is no longer editable by default, and Django rejects definitions that request a non-default driver. Upgrade to 6.1.4, 6.0.11 or 5.2.20.
CVECVE-2026-124827 (“Django4Shell”)
SeverityHigh per Django; CVSS 3.1: 8.8 (Snyk)
ComponentGeoDjango RasterField (PostGIS)
ImpactArbitrary file write, RCE depending on the GDAL driver
Affected versions5.2 < 5.2.20, 6.0 < 6.0.11, 6.1 < 6.1.4
Fixed in5.2.20, 6.0.11, 6.1.4 (2 Dec 2026)
Reported byMohammed Fathy
ExploitationNo active exploitation reported as of 2 Dec 2026

MITRE ATT&CK mapping

T1190Exploit Public-Facing Application
T1546.018Event Triggered Execution: Python Startup Hooks
T1059.006Command and Scripting Interpreter: Python
T1505.003Server Software Component: Web Shell

This is an indicative Defensy mapping based on the behaviours described. The entry point is an exposed application (T1190): a form, the admin or an API that accepts a RasterField. Persistence and execution rely on a Python startup hook (T1546.018), a .pth or sitecustomize.py file, whose content is Python code (T1059.006). According to the researcher quoted by Snyk, the same write can also drop a web shell (T1505.003) into a static files directory.

Background: GeoDjango, RasterField and GDAL

GeoDjango is Django’s module for geographic data. It provides geometry fields (points, polygons…) and a RasterField for raster data such as georeferenced images or digital elevation models. This field is only implemented for PostGIS and relies on the GDAL library to read and write rasters.

GDAL works with drivers. The default driver, MEM, works in memory. Other drivers, such as EHdr mentioned by Snyk, write the raster to a file on disk, at the path given by the definition’s name parameter.

This is the third fix on the same attack surface. According to Snyk, CVE-2026-15307 (August 2026) already addressed file writes and outbound requests through raster values in spatial lookups, and CVE-2026-87890 (October 2026) a request forgery case. An application patched in August therefore needs another update.

Root cause analysis

  1. A field editable by default

    Because RasterField falls back to the CharField form field, it appears automatically in the admin, in ModelForms and in writable model serializers. According to the Django advisory, the flaw was therefore reachable “by default”.

  2. No restriction on the driver or the path

    Before the fix, Django passed the definition’s name parameter to GDAL without restricting the driver. With a driver that writes to disk, GDAL creates the file at the given path, including with ../ sequences.

  3. A file write that becomes code execution

    A file placed in a sys.path directory, such as a .pth in site-packages or a sitecustomize.py, runs when the interpreter starts. A worker restart, a server reload, a manage.py command or a scheduled job is then enough to run the code.

The attack chain

This is the chain as we reproduced it. The attacker needs network access to an entry point that accepts an editable RasterField.

1

Checking the write primitive

T1190

The exploit submits a raster definition that requests a GDAL driver writing to disk. If the request is accepted, file writes are possible. On a patched version, Django raises a GDALException.

2

Dropping the .pth file

T1546.018 T1059.006

The exploit writes a .pth file into the site-packages directory. Python runs this type of file every time the interpreter starts.

3

Triggering a restart

The code only runs the next time Python starts. In our reproduction, the exploit makes the Django server reload. In production, a worker restart, a deployment or a scheduled job has the same effect.

4

Execution and output retrieval

At startup, Python processes the .pth and runs the attacker’s command. In our test environment, the id command returned uid=0(root), because the application ran as root inside its container. No direct access to the server is needed.

Demonstration: the proof of concept on video

The video below shows the full chain against a deliberately vulnerable test application, in an isolated environment.

Reading notes. Django rates the flaw “high” severity and does not publish a CVSS score in its advisory. Snyk scores it 8.8 (CVSS 3.1) and 8.7 (CVSS 4.0), while the researcher’s website presents it as “critical”. The privilege level required depends on how the field is exposed: a staff account is enough through the admin, but a public form or API widens the exposure. Unsupported versions (4.2, 5.0, 5.1) were not evaluated by Django and may also be affected. As of 2 December 2026, no active exploitation had been reported and the flaw was not in the CISA KEV catalog.

Who is exposed

  • Applications using the Django admin: a staff user who can add or change a model containing a RasterField can trigger the flaw. Superuser rights are not needed.
  • REST APIs: a writable model serializer includes the field. If the endpoint accepts weakly authenticated or anonymous users, the exposure grows accordingly.
  • Public forms: any ModelForm that includes a RasterField and is reachable by external users.
  • Containers running as root: the code runs with the rights of the Python process. In a container started as root, the attacker directly gets root inside the container.

Out of scope: applications that do not use GeoDjango, those that do not use RasterField, and geometry fields (PointField, PolygonField…).

What the fix changes

BranchAffected versionsFixed version
Django 6.1before 6.1.46.1.4
Django 6.0before 6.0.116.0.11
Django 5.2 (LTS)before 5.2.205.2.20
4.2, 5.0, 5.1not evaluated by Djangomove to a supported branch

RasterField now has editable=False by default: it no longer appears in a ModelForm unless explicitly included. Django also raises a GDALException when a dict or JSON string requesting a non-default driver is assigned. To use another driver, wrap the definition in GDALRaster to mark the value as trusted. Django notes that this protection only prevents file writes: server-side request forgery (SSRF) is still possible if untrusted input is assigned to RasterField.

The same release fixes six other vulnerabilities, including CVE-2026-132092, a high-severity SQL injection in range and in lookups. The update is worth applying even without GeoDjango.

Recommendations

  1. ImmediateUpgrade Django

    Move to 6.1.4, 6.0.11 or 5.2.20, then rebuild and redeploy your images. Check the version with python -m django --version. Applications on 5.1 or older must move to a supported branch.

  2. ImmediateIf the upgrade must wait, remove the field from forms

    Add editable=False to every RasterField or explicitly exclude it from forms, the admin and serializers. Restrict admin access to the affected models.

  3. Short termLook for signs of exploitation

    In the logs of raster endpoints, look for requests containing ../, /vsi or EHdr. On servers, look for unexpected .pth or sitecustomize.py files and for application files changed without a matching deployment.

  4. Short termInventory RasterField usage

    Search the code for RasterField (grep -rn "RasterField" --include=*.py .) and list every form, admin view and serializer that exposes it, with its permissions.

  5. Medium termValidate raster input and limit SSRF

    SSRF remains possible after the fix. Validate raster definitions in the application, use GDALRaster only for trusted values and filter outbound traffic from application servers.

  6. Medium termApply least privilege

    Do not run Django as root in containers, make site-packages and the application code read-only for the web process, and limit writes to the directories that strictly need them.

Indicators to watch

  • Unexpected .pth or sitecustomize.py files in site-packages or a sys.path directory, especially if they contain imports or system calls. Critical
  • Requests to a raster endpoint containing a driver other than MEM, EHdr, ../ or /vsi. Critical
  • GDAL sidecar files (.hdr, .prj) appearing in application or system directories. Suspicious
  • Application or static files changed without a matching deployment. Suspicious
Defensy’s view

Django4Shell is not a GDAL bug but a missing control between Django and GDAL: an ordinary form field was wired to a library able to write to disk. The fix is simple, but an application patched in August against CVE-2026-15307 remains exposed until it is updated again.

Our Audit & Offensive Security team reproduced this chain and now includes it in penetration tests of Django applications. Our SOC, Detection & Response offer helps you monitor the indicators above on your exposed servers.

CVE-2026-124827 RCE Django GeoDjango GDAL PostGIS Patch available