Blogs

Django4Shell (CVE-2026-124827): GeoDjango Fix and Checklist

  • Django
  • Security
  • Python
  • Backend Development
Dark graphic titled Django4Shell CVE-2026-124827 with a raster data definition whose driver and name keys are highlighted, next to the fixed versions Django 6.1.4, 6.0.11 and 5.2.20

In short: Django4Shell (CVE-2026-124827) is a high-severity GeoDjango flaw: assigning a user-controlled raster definition with a non-MEM driver to a RasterField makes GDAL write a file wherever the attacker says, which can lead to remote code execution. Only PostGIS projects whose RasterField is reachable through the admin, a ModelForm or a writable serializer are exposed. Upgrade to Django 6.1.4, 6.0.11 or 5.2.20.

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:

  1. You use GeoDjango with PostGIS. RasterField is only implemented on PostGIS. Geometry fields (PointField, PolygonField and so on) are not affected.
  2. At least one model has a RasterField.
  3. That field is writable from outside: registered in the admin, included in a ModelForm, or exposed in a writable DRF serializer. Django notes that RasterField falls back to the CharField form field, so before the patch it showed up in the admin and in fields = "__all__" forms by default.
  4. 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:

  1. RasterField now defaults to editable=False. It no longer appears in the admin or in ModelForms unless you explicitly ask for it.
  2. Dictionaries and JSON strings must use the MEM driver. Anything else raises GDALException: Only in-memory (MEM) data definitions can be assigned to RasterField. If you really need a file driver, wrap the definition in GDALRaster() 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=False to every RasterField in your models. This is a standard field option, so it works on any version.
  • Remove the field from ModelAdmin.fields, any ModelForm.Meta.fields list and any serializer fields, or add it to read_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 the GDALRaster on 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:

CVEIssueSeverity
CVE-2026-124827File write via RasterField assignment (Django4Shell)High
CVE-2026-132092SQL injection in range and in lookupsHigh
CVE-2026-115868XSS in truncatechars_html and Truncator.chars(html=True)Moderate
CVE-2026-125673Cache poisoning via dot segments in build_absolute_uri()Low
CVE-2026-119642Admin changelist data leak via the pk alias on OneToOneFieldLow
CVE-2026-127929Admin changelist data leak via reverse relationsLow
CVE-2026-132809Heap overflow in OGRGeometry.wkbLow

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

Related reading

Frequently asked questions

Is Django4Shell exploitable without logging in?
Django’s advisory does not state an authentication requirement. The default exposure is the admin and ModelForms, so it depends on who can submit them. A RasterField in a writable serializer on a public API endpoint would be reachable by anyone who can call that endpoint.
Does Django4Shell affect projects without GeoDjango?
No. The flaw is in django.contrib.gis RasterField, which only exists on the PostGIS backend. Projects that do not use RasterField are not affected by this CVE, although they should still upgrade for the other fixes in the same release.
Which Django versions fix CVE-2026-124827?
Django 6.1.4, 6.0.11 and 5.2.20, released on December 2, 2026. Series older than 5.2 are out of support and get no patch, so upgrade to a supported series.
Is the SQL injection fixed in the same release more urgent?
It affects far more projects. CVE-2026-132092, an SQL injection in range and in lookups, is also rated high and does not need GeoDjango, so the same upgrade is urgent even if you never touch rasters.

Tell me about your next project

Have an AI agent, a backend or a full product in mind? Send a short note and we can talk it through.