This is the English adaptation of the original Korean analysis at dohyeontech.github.io.

On 2 December 2026 the Django team shipped 6.1.4, 6.0.11 and 5.2.20 with seven security fixes. Two are rated "high" under Django's own policy; this piece is about the GeoDjango one. CVE-2026-124827: assigning a raster data definition to RasterField can make GDAL write a file to a path the attacker controls. CWE-73 (external control of file name or path), CAPEC-76. Reported by Mohammed Fathy of Robusta Technology Group, who nicknamed it Django4Shell before disclosure.

One sentence: a staff user posts a JSON blob to a form, and before the request ever reaches the database, the server writes attacker-chosen bytes to an attacker-chosen path. Django had already fixed the same sink in the same module twice — in August and October — and both times the advisory said, in effect, that the fix covered the query path. The third round closed the assignment path.

1. The hole that August left open on purpose

This is not a regression in new code. It is the last piece of a fix that was split across three releases.

Date What shipped
2026-08-04 Django 6.0.8 / 5.2.17 — CVE-2026-15307. Spatial lookups could pass dict and str values into GDALRaster; those were blocked. The advisory states plainly that "assignments to model fields are unaffected and still accept these input types"
2026-10-06 Django 6.1.2 / 6.0.9 / 5.2.18 — CVE-2026-87890. bytes values in lookups could smuggle a VRT document that fetches an external URL. The advisory says the issue "was overlooked in the fix for CVE-2026-15307"
2026-12-02 Django 6.1.4 / 6.0.11 / 5.2.20 — CVE-2026-124827. The assignment path. Third round

That August sentence explains the December CVE better than the December advisory does. What Django hardened in August was the path where a value travels through a query — filter(rast=...). Assigning a value to a model field was left open on the explicit premise that the application validates its own input. December's patch is an admission that the premise did not hold in practice.

What is established, and what is not:

Item Status
Affected versions Confirmed — 6.1 before 6.1.4, 6.0 before 6.0.11, 5.2 before 5.2.20. RasterField exists only on the PostGIS backend; geometry fields are unaffected
Unsupported series Not evaluated by the vendor — the CVE text says 5.1.x, 5.0.x and 4.2.x were not assessed and "may also be affected"
Severity Confirmed — "high" under Django policy. CVE record: CVSS 3.1 8.8, CVSS 4.0 8.7
Preconditions Confirmed — django.contrib.gis plus a RasterField model, that field reachable through a form, the admin, or a writable serializer, a standard GDAL build (EHdr is compiled in), and a writable target path
Exploitation in the wild Not observed — no vendor, CVE or Snyk reporting of attacks, one day after disclosure
Public exploit Confirmed — a third-party repo with a Docker lab, Nuclei template and Nmap NSE script appeared within hours
The "9.0" in some coverage Discrepancy — the CVE record carries 8.8/8.7; the researcher's page says P1; the vendor rating is "high"

2. One sink, two doors, and a guard on only one of them

Every raster value in GeoDjango reaches GDAL through exactly one constructor: GDALRaster(ds_input). The problem is that this constructor cannot tell whether its input is trusted. So every defense has been bolted onto a caller instead.

The lookup path got a gate in August. BaseSpatialField.get_raster_prep_value() in django/contrib/gis/db/models/fields.py calls check_raster_lookup_value() before it constructs anything:

# django/contrib/gis/db/models/fields.py — BaseSpatialField.get_raster_prep_value() def get_raster_prep_value(self, value, is_candidate): if isinstance(value, gdal.GDALRaster): return value gdal.GDALRaster.check_raster_lookup_value(value) # dict/str/Path/bytes -> DisallowedRasterLookup if is_candidate: try: return gdal.GDALRaster(value) except GDALException: pass return None 

check_raster_lookup_value() rejects dict, str, Path and bytes outright. If you trust a value, you wrap it in GDALRaster() yourself and say so. The reason August needed that gate is specific: the admin changelist permits filtering through ModelAdmin.lookup_allowed(), so a staff user with view-only permission on a model containing a spatial field could reach it.

The assignment path never had a gate. SpatialProxy in django/contrib/gis/db/models/proxy.py is a descriptor. It stores what you give it and only builds the real object when someone reads the attribute:

# django/contrib/gis/db/models/proxy.py — SpatialProxy def __set__(self, instance, value): ... instance.__dict__[self.field.attname] = value # stored as-is, no checks def __get__(self, instance, cls=None): ... geo_obj = self._load_func(geo_value) # GDALRaster(...) happens here setattr(instance, self.field.attname, geo_obj) 

The silence in __set__ is a side effect of lazy evaluation, not laziness. It exists so that loading a large queryset does not instantiate every raster up front. The cost of that design is that "assigning a value" and "creating a file" become two separate events, and the second one happens at a place the developer is not looking at. That is why this vulnerability triggers during form validation rather than at model.save().

3. Where assignment becomes a file: the dict branch of GDALRaster.__init__

GDALRaster.__init__ splits four ways by input type. A string opens an existing file, bytes creates a VSI in-memory file, and a dict creates a new dataset in write mode. That last branch is ours:

# django/contrib/gis/gdal/raster/source.py — GDALRaster.__init__ (dict branch) elif isinstance(ds_input, dict): self._write = 1 driver = Driver(ds_input.get("driver", "MEM")) # in-memory by default if driver.name != "MEM" and "name" not in ds_input: raise GDALException('Specify name for creation of raster with driver "%s".' % driver.name) ... self._ptr = capi.create_ds( driver._ptr, force_bytes(ds_input.get("name", "")), # <- this string becomes a file path ds_input["width"], ds_input["height"], ds_input.get("nr_of_bands", len(ds_input.get("bands", []))), ds_input.get("datatype", 6), byref(papsz_options), ) 

With the default MEM driver, name is just a label. The moment the input picks a different driver, name is promoted to a path — and the input itself makes that decision. name is passed through force_bytes into GDALCreate() unchanged.

Where the file lands and what it is called is the driver's business. The researcher chose EHdr (ESRI .hdr Labelled). In GDAL 3.13, frmts/raw/ehdrdataset.cpp shows a very simple creation path:

/* ehdrdataset.cpp — EHdrDataset::Create() */ VSILFILE *fp = VSIFOpenL(pszFilename, "wb"); // opens the name exactly as given (:1664) ... bool bOK = VSIFWriteL("\0\0", 2, 1, fp) == 1; // two bytes to establish the file ... const std::string osHdrFilename = CPLResetExtensionSafe(pszFilename, "hdr"); // sidecar .hdr (:1684) 

The data file is opened under exactly the name supplied, with no extension added. So name: "/app/sitecustomize.py" produces a file with that name, and the band data is written into it. With datatype: 1 (GDT_Byte), the band array is a byte array — which means the payload can be Python source. Band.data() writes through capi.band_io() and immediately calls _flush() (django/contrib/gis/gdal/raster/band.py), so creation and persistence are the same step. There is no later flush to wait for.

The JSON that does this looks like this. This is the shape the researcher published, with the band bytes elided:

{ "driver": "EHdr", "name": "/app/<target filename>", "width": 64, "height": 1, "srid": 4326, "nr_of_bands": 1, "datatype": 1, "origin": [0, 0], "scale": [1, -1], "bands": [{ "data": [ /* bytes to write */ ] }] } 

One caveat worth stating. The public exploit repo's README describes the data file as <name>.bil, while the Create() code above opens the name verbatim. I could not reproduce either claim here — this environment has no GDAL build. What survives the ambiguity is the same: the request body decides a substantial part of where the file goes and what it is called, and nothing on the server validates that decision.

4. No database, no save() — validation is enough

RasterField has no form field of its own. Field.formfield() falls back to forms.CharField when form_class is unset (django/db/models/fields/__init__.py:1188). So in an auto-generated admin form the field is a plain text input, and a JSON string passes straight through. No upload widget, no format check.

Django's ModelForm reads every model field once during validation:

# django/db/models/base.py — Model.clean_fields() (:1776) for f in self._meta.fields: if f.name in exclude or f.generated: continue raw_value = getattr(self, f.attname) # <- SpatialProxy.__get__ runs here 

Follow the order of calls:

POST /admin/app/rastermodel/add/ └─ ModelForm.is_valid() └─ _post_clean() ├─ construct_instance() -> setattr(instance, "rast", '{"driver": "EHdr", ...}') └─ instance.full_clean(exclude=...) └─ clean_fields() └─ getattr(instance, "rast") # descriptor __get__ └─ SpatialProxy._load_func(value) └─ GDALRaster(dict) # write=1, non-default driver └─ GDALCreate(EHdr, "/app/sitecustomize.py", ...) └─ file created, band bytes written 

model.save() has not been called. No connection, no table, no PostGIS extension is involved. The form reads the value in order to validate it, and the read creates the file. That reframes the exposure: it is not "a user who can save", it is "a user who can submit that form". In the admin that means a staff account; on an API that exposes the same model through a writable serializer, the boundary is whatever the application's auth layer says it is. The "staff" in the CVE's precondition list describes the admin path, not the essence of the bug.

What happens after the file lands is Python's business. A sitecustomize.py in the working directory or anywhere on sys.path is imported automatically at interpreter startup; a .pth file dropped into site-packages achieves the same thing. A gunicorn worker restart, a runserver reload, or one manage.py cron run from the same codebase executes it with the privileges of the web server's OS user. The researcher notes that the same primitive can drop a web shell into a static directory or overwrite application source. That is why this does not stop at "file write".

5. What the patch actually enforces

The fix is four commits — main a3934abd, 6.1 b70d0988, 6.0 6b5d29ea, 5.2 02d09443 — and one file, with two layers:

# django/contrib/gis/db/models/fields.py — RasterField after the fix class RasterField(BaseSpatialField): def __init__(self, *args, **kwargs): kwargs.setdefault("editable", False) # (1) out of forms by default super().__init__(*args, **kwargs) def deconstruct(self): name, path, args, kwargs = super().deconstruct() if self.editable: kwargs["editable"] = True else: del kwargs["editable"] # no migration churn return name, path, args, kwargs def contribute_to_class(self, cls, name, **kwargs): ... setattr(cls, self.attname, SpatialProxy(gdal.GDALRaster, self, self.init_raster)) # (2) new read hook def init_raster(self, ds_input): value = gdal.GDALRaster._preprocess_input(ds_input) # JSON string -> dict if (isinstance(value, dict) and (driver := value.get("driver", "MEM")) is not None and Driver(driver).name != "MEM"): raise GDALException( "Only in-memory (MEM) data definitions can be assigned to " f"RasterField (got: {driver!r}). Wrap the definition in " "GDALRaster() to use another driver.") return gdal.GDALRaster(value) 

The two layers do different jobs. (1) reduces exposure: with editable=False the field cannot appear in a ModelForm under fields = "__all__" or in an auto-generated admin form, and _get_validation_exclusions() drops it, so clean_fields() never performs that getattr. The original trigger — a write during form validation — is severed by this one line. (2) is the actual boundary: SpatialProxy's loader becomes init_raster, so every read through the descriptor rejects a non-default driver in a dict or JSON string. Whether the caller is a serializer, a management command, or code written next year, it passes the same check.

The deconstruct() override is the interesting detail. Field.deconstruct() emits only values that differ from the field default, and Field's default for editable is True. If RasterField silently changes it to False, every existing model suddenly looks like it changed, and makemigrations prints meaningless AlterField operations. The override deletes editable again when it is False. A security fix with migration hygiene attached — and this is the part operators will actually notice.

What the patch does not do deserves equal clarity:

Change Blocks / does not block
Rejecting non-default drivers in dict/JSON Blocks server-side file writes on the assignment path
editable=False by default Reduces form and admin exposure. Set editable=True and it is open again
Advisory keeps its warning Remains — Django states SSRF is still possible when untrusted input is assigned
Unsupported series Not evaluated — 5.1.x, 5.0.x, 4.2.x still behave the old way

The SSRF residue is visible in the code. The string branch of GDALRaster.__init__ checks os.path.exists() to decide whether it has a local path, but a /vsicurl/ or /vsizip/ prefix skips that check and GDALOpen() makes a network request. The new exception only restricts the driver of a dict, so a string input can still fetch. The release notes say exactly that, and they are right.

There is an operational cost too. Because editable=False is now the default, existing apps that edited rasters in the admin lose that input after upgrading. If you need it, set RasterField(editable=True) explicitly and add your own validation per the raster security considerations in the docs. It is a quiet behavior change worth checking before you deploy.

6. What to do now

If you can patch, patch first. 5.2 is the LTS line; 6.0 and 6.1 are current.

pip install -U "Django>=6.1.4" # >=6.0.11 on 6.0, >=5.2.20 on 5.2 python -c "import django; print(django.get_version())" 

Then confirm the migration state is clean and that any raster editing screen still exists.

If you cannot upgrade today, cut the exposure. The bug requires three things at once: the field is visible in a form, a value gets assigned, and that value gets read.

  • Remove RasterField from the admin with exclude / readonly_fields, and from ModelForm.Meta.exclude.
  • If a writable serializer accepts the raster field, make it read-only or reject incoming dict/JSON in validation.
  • Run the process with --config GDAL_SKIP EHdr (or GDAL_SKIP=EHdr). Treat this as secondary: GTiff, PNG, HFA and other writing drivers remain. The real boundary is not accepting a dict at all.
  • In containers, mount the application directory and site-packages read-only. The goal is to remove anywhere a sitecustomize.py or .pth could sit.

There is a usable detection artifact. The EHdr driver writes a sidecar .hdr text file next to the data file. A successful attack leaves a stray .hdr with ncols, nrows, cellsize in an application directory.

find /app /srv -xdev -name '*.hdr' -newermt '-14 days' -exec head -c 200 {} \; find / -xdev -name 'sitecustomize.py' -newer /app/manage.py 2>/dev/null 

sitecustomize.py can exist legitimately, so the question is not presence but when it appeared and who wrote it. Pair that with recent admin POSTs from staff accounts, worker restarts in the same window, and any unexpected outbound process from the container.

7. What the third round leaves behind

Splitting one sink across three releases does not mean the maintainers were careless. The August advisory said "assignments are unaffected" explicitly, and that was an accurate reading of the code at the time. The judgement was: put the gate on the query API, leave field assignment to applications. October exposed the gap in that judgement (bytes and VRT). December exposed the other half.

What keeps surfacing is not a mistake in judgement but where the boundary was drawn. GDALRaster(ds_input) cannot know whether its input is trusted, so defense becomes a matter of enumerating callers and checking each one. Every new caller repeats the review, and one omission reproduces this CVE. This patch does not seal the sink either; it adds a check to one caller — the field. That is why the documentation repeats the instruction not to hand untrusted input to GDALRaster() directly.

GeoDjango and PostGIS deployments are not common, but the ones that exist tend to hold public data: mapping, land, environment, agriculture. Staff accounts there carry GIS edit permission, and until now that permission has been understood as "can change data". After this, it has to be classified as "can write files on the server".

References

Original Korean analysis: Django4Shell — 조회는 막았고, 대입은 열려 있었다