Django4Shell is the name the researcher gave CVE-2026-124827, a GeoDjango bug that Django patched on December 2, 2026. If your project stores rasters in a PostGIS RasterField and that field is writable from the admin, a ModelForm or an API serializer, an attacker can make GDAL write a file to a path of their choosing on your server. Depending on the GDAL driver, that can become remote code execution.
The fix is a normal upgrade: Django 6.1.4, 6.0.11 or 5.2.20. Below is what the bug is, how to tell in two minutes whether you are exposed, and what to do if you cannot deploy today.
You’ll learn:
- What Django4Shell is and what Django itself says about it
- How to tell whether your project is affected, with a script you can paste into
manage.py shell - Why assigning a dictionary to a model field can write a file
- What the patch changes, including one upgrade gotcha
- What the patch does not fix, and the six other CVEs in the same release
What is Django4Shell?
Django4Shell is CVE-2026-124827, officially titled “Server-side file-write via RasterField assignment”, and Django rates it severity “high” under its security policy. It was reported by Mohammed Fathy and fixed in Django 6.1.4, 6.0.11 and 5.2.20 (and on main).
From the release notes: assigning a raster data definition to RasterField “with a user-controlled name parameter and a non-default driver could cause GDAL to write a file to an attacker-controlled location. Depending on the raster driver, this could enable remote code execution.”
The “Django4Shell” name comes from the researcher’s own disclosure, not from Django. Some press coverage quotes a CVSS score of 9.0 (“critical”); Django’s advisory publishes no CVSS score, only its own “high” rating. Plan around the advisory, not the headline.
Am I affected by CVE-2026-124827?
You are affected only if all four of these are true:
- You use GeoDjango with PostGIS.
RasterFieldis only implemented on PostGIS. Geometry fields (PointField,PolygonFieldand so on) are not affected. - At least one model has a
RasterField. - That field is writable from outside: registered in the admin, included in a
ModelForm, or exposed in a writable DRF serializer. Django notes thatRasterFieldfalls back to theCharFieldform field, so before the patch it showed up in the admin and infields = "__all__"forms by default. - You run a Django version below 6.1.4, 6.0.11 or 5.2.20 in your series, or any series older than 5.2.
If you are not sure, run this in python manage.py shell (or pipe it in with python manage.py shell < raster_audit.py):
# raster_audit.py: list every RasterField and how it can be written to.
# Run with: python manage.py shell < raster_audit.py
import django
from django import forms
from django.apps import apps
from django.contrib import admin
FIXED = {(6, 1): (6, 1, 4), (6, 0): (6, 0, 11), (5, 2): (5, 2, 20)}
def is_patched(version):
fixed = FIXED.get(tuple(version[:2]))
if fixed is None:
return tuple(version[:2]) > (6, 1) # older series are out of support
return tuple(version[:3]) >= fixed
def subclasses(cls):
for sub in cls.__subclasses__():
yield sub
yield from subclasses(sub)
def listed(meta, name):
fields = getattr(meta, "fields", None)
exclude = getattr(meta, "exclude", None) or ()
return (fields == "__all__" or name in (fields or ())) and name not in exclude
try:
from rest_framework import serializers
serializer_classes = list(subclasses(serializers.ModelSerializer))
except ImportError:
serializer_classes = []
print(f"Django {django.get_version()}: {'patched' if is_patched(django.VERSION) else 'NOT patched, upgrade'}")
for model in apps.get_models():
for field in model._meta.get_fields():
if getattr(field, "get_internal_type", lambda: "")() != "RasterField":
continue
print(f"\n{model._meta.label}.{field.name} editable={field.editable}")
model_admin = admin.site._registry.get(model)
if model_admin and field.editable:
hidden = field.name in (model_admin.exclude or ()) or field.name in model_admin.readonly_fields
print(f" admin: {type(model_admin).__name__} ({'hidden' if hidden else 'WRITABLE'})")
for form in subclasses(forms.ModelForm):
meta = getattr(form, "_meta", None)
if meta and meta.model is model and field.name in form.base_fields:
print(f" ModelForm: {form.__module__}.{form.__name__}")
for ser in serializer_classes:
meta = getattr(ser, "Meta", None)
if getattr(meta, "model", None) is model and listed(meta, field.name) \
and field.name not in getattr(meta, "read_only_fields", ()):
print(f" serializer: {ser.__module__}.{ser.__name__}")
No output after the version line means no RasterField at all. A line marked WRITABLE, a ModelForm or a serializer under a field is an exposure to fix.
How I tested it: I ran it on Django 5.2.7 and DRF 3.16.1 against a small test app, with a stand-in field that reports itself as RasterField (the real one needs GDAL and PostGIS). It correctly flagged a writable admin, a fields = "__all__" form and a writable serializer, and skipped a read-only one. I have not run it on a production GeoDjango project. Two limits: it only sees forms and serializers whose modules are already imported (the admin is loaded automatically, your forms.py and serializers.py may not be), and it reads the serializer’s Meta, so fields you declare by hand are not checked.
How does a RasterField assignment write a file?
RasterField accepts anything the GDALRaster constructor accepts, including a dictionary (or the same thing as a JSON string) that describes a new raster. That description has a driver key and a name key. With the default MEM driver the raster lives in memory. With a file driver such as GTiff, GDAL creates a real file, and name is the path it writes to.
Django’s own patched documentation shows the shape:
dem = Elevation.objects.create(
name="Canyon",
rast={
"driver": "tif",
"name": "canyon.tif",
"width": 10,
"height": 10,
"srid": 4326,
"scale": [0.1, -0.1],
"bands": [{"data": range(100)}],
},
)
On a patched version this now raises GDALException. On an unpatched one it writes canyon.tif to disk. Now picture the dictionary coming from a form post or a JSON body: the attacker picks name, so the attacker picks where the file lands. Because the admin and ModelForm render RasterField as a plain text input, a JSON string typed into that box was enough.
This is the same class of problem as an upload handler that trusts a client-supplied filename, which I covered in the file upload security guide: never let user input choose a path on your server.
What does the patch change?
The fix (commit a3934abd on main, backported to each series) does two things:
RasterFieldnow defaults toeditable=False. It no longer appears in the admin or inModelForms unless you explicitly ask for it.- Dictionaries and JSON strings must use the
MEMdriver. Anything else raisesGDALException: Only in-memory (MEM) data definitions can be assigned to RasterField. If you really need a file driver, wrap the definition inGDALRaster()yourself, which tells Django the value is trusted.
The upgrade gotcha: if your code relied on the old default, the field silently disappears from the admin and from fields = "__all__" forms. If a form or ModelAdmin lists the field by name, Django raises FieldError because you cannot put a non-editable field in a form. That error is the patch doing its job. Decide whether users should really be submitting rasters, and if so, write explicit validation.
What should I do right now?
Upgrade. Pick the line for your series:
pip install "Django>=6.1.4,<6.2" # 6.1 series
pip install "Django>=6.0.11,<6.1" # 6.0 series
pip install "Django>=5.2.20,<5.3" # 5.2 LTS
Then run your test suite and re-run the audit script: every RasterField should show editable=False.
If you cannot deploy today, close the door by hand:
- Pass
editable=Falseto everyRasterFieldin your models. This is a standard field option, so it works on any version. - Remove the field from
ModelAdmin.fields, anyModelForm.Meta.fieldslist and any serializerfields, or add it toread_only_fields. - Never assign a user-supplied dictionary or string to a
RasterField. If users upload raster files, save the upload safely first and build theGDALRasteron the server.
What does the patch not fix?
Server-side request forgery. Django says so directly: the new check “only limits server-side file writes. Server-side request forgery is still possible if untrusted input is assigned to RasterField.” GDAL can read rasters from URLs, so a user-controlled value can still make your server fetch an address of the attacker’s choosing, including internal services. The rule from the raster security considerations in Django’s docs stands: validate before any untrusted input reaches RasterField.
This is also not the first GeoDjango security fix this year. CVE-2026-15307 (August) covered file writes and SSRF through spatial lookups. Those fixes hardened lookups, not field assignment, which is the path Django4Shell used.
Which other CVEs are in this release?
Django 6.1.4, 6.0.11 and 5.2.20 fix seven security issues in total. Most projects should care more about the SQL injection than about Django4Shell, because it needs no GeoDjango:
| CVE | Issue | Severity |
|---|---|---|
| CVE-2026-124827 | File write via RasterField assignment (Django4Shell) | High |
| CVE-2026-132092 | SQL injection in range and in lookups | High |
| CVE-2026-115868 | XSS in truncatechars_html and Truncator.chars(html=True) | Moderate |
| CVE-2026-125673 | Cache poisoning via dot segments in build_absolute_uri() | Low |
| CVE-2026-119642 | Admin changelist data leak via the pk alias on OneToOneField | Low |
| CVE-2026-127929 | Admin changelist data leak via reverse relations | Low |
| CVE-2026-132809 | Heap overflow in OGRGeometry.wkb | Low |
The takeaway
Upgrade to 6.1.4, 6.0.11 or 5.2.20 today: the SQL injection alone justifies it. If you run GeoDjango, run the audit script, look for any RasterField your users can write to, and treat every raster value from outside your server as untrusted, because the patch stops file writes but not SSRF. If you would like a second pair of eyes on a Django backend, that is part of my backend development work.
Sources
- Django security releases issued: 6.1.4, 6.0.11, and 5.2.20 (Django Project weblog, December 2, 2026)
- Fix commit a3934abd (django/django on GitHub)
- Django 5.2.20 release notes
- GeoDjango GDAL API: raster data source objects
Related reading
- File Upload Security Best Practices (2026 Checklist)
- N+1 Queries in Django ORM: Find Them, Then Kill Them



