Django4Shell: GeoDjango RCE, Fixed in 6.1.4 (CVE-2026-124827)
Django 6.1.4, 6.0.11 and 5.2.20 fix Django4Shell, a GeoDjango RasterField file-write-to-RCE, and a Critical SQL injection.
TL;DR
- Django 6.1.4, 6.0.11 and 5.2.20 fix seven flaws. The lead is Django4Shell (CVE-2026-124827), a GeoDjango RasterField file write that can execute code. The CVE record carries CVSS v3.1 8.8, and Django's policy rates it High.
- The same release fixes CVE-2026-132092, a SQL injection in
rangeandinlookups that the CVE record scores CVSS v3.1 9.8 Critical. It needs a specific query shape and an attacker-controlled lookup value. - Django 6.1 before 6.1.4, 6.0 before 6.0.11 and 5.2 before 5.2.20 are affected. The RCE needs a staff account, a RasterField exposed through a ModelForm or the admin, and a writable path on the server.
- No in-the-wild exploitation is reported, and neither CVE is in CISA KEV as of 2026-12-02. Upgrade to the fixed release for your branch; "How do I fix it?" covers the interim controls.
Am I affected?
All of these must hold:
- The project runs Django 6.1 before 6.1.4, Django 6.0 before 6.0.11, or Django 5.2 before 5.2.20.
- For Django4Shell,
django.contrib.gisis installed and a model declares aRasterField. - The RasterField is exposed through a ModelForm, the Django admin, or a writable serializer, and a staff-level user can submit the form.
- The server has GDAL with the EHdr driver, which standard GDAL builds include, and the Django process can write to a directory on Python's import path.
- For CVE-2026-132092, application code uses
__rangewith more than two values or__inwith a bilateral transform, and a query alias or key transform contains a percent sign.
RasterField is implemented only on PostGIS, but the file write happens during form validation, before any database write. The researcher says the form path needs no PostGIS connection and no database table. The SQL injection depends on the application's query construction, not on GeoDjango.
| Branch | Affected versions | Fixed version |
|---|---|---|
| 6.1.x | 6.1 before 6.1.4 | 6.1.4 |
| 6.0.x | 6.0 before 6.0.11 | 6.0.11 |
| 5.2.x (LTS) | 5.2 before 5.2.20 | 5.2.20 |
| 5.1.x, 5.0.x, 4.2.x | unsupported; not evaluated and may be affected | no fixed release; upgrade to a supported branch |
Django evaluated three supported branches. It did not evaluate the unsupported 5.1.x, 5.0.x and 4.2.x series, and its advisory says they may also be affected.
| CVE | Flaw | CVSS v3.1 |
|---|---|---|
| CVE-2026-132092 | SQL injection in range and in lookups |
9.8 Critical |
| CVE-2026-124827 | RasterField assignment file write to RCE | 8.8 High |
| CVE-2026-115868 | XSS in truncatechars_html |
6.1 Medium |
| CVE-2026-132809 | Heap overflow in OGRGeometry.wkb |
5.3 Medium |
| CVE-2026-125673 | Cache poisoning via dot segments | 3.7 Low |
| CVE-2026-119642 | Admin changelist leak via pk alias |
2.7 Low |
| CVE-2026-127929 | Admin changelist leak via reverse relations | 2.7 Low |
Django's release notes rate two issues high, one moderate and four low. The CVE records carry the scores in the table, and they range from 9.8 to 2.7.
Check the installed version, whether GeoDjango is loaded, and where the project declares a RasterField:
python -c "import django; print(django.get_version())"
python -c "import django.contrib.gis; print('GeoDjango installed')"
grep -rn "RasterField" --include="*.py" .
Check the version recorded in the dependency files as well, because a virtual environment can differ from the lock file:
python -m pip show django
grep -iE '^django([=<>!~ ]|$)' requirements*.txt
poetry show django 2>/dev/null
pipenv graph 2>/dev/null | grep -i django
How do I fix it?
Upgrade to the fixed release for the branch: 6.1.4 for 6.1.x, 6.0.11 for 6.0.x and 5.2.20 for 5.2.x. The advisory and the release notes are on the Django security releases page.
- Read the installed version and choose the fixed release for its branch.
- Upgrade Django with the package manager the project uses.
- Rebuild the lock file and redeploy every web and background worker.
- Run the test suite, including the GIS tests when the project uses GeoDjango.
- Confirm the new version on each running instance.
Use the line that matches the branch you are on. For pip:
python -m pip install --upgrade "Django==6.1.4"
python -m pip install --upgrade "Django==6.0.11"
python -m pip install --upgrade "Django==5.2.20"
For a project that pins a range rather than an exact version:
python -m pip install --upgrade "Django>=6.1.4,<6.2"
For Poetry, change the constraint in pyproject.toml to the fixed release, then run poetry lock and poetry install. For Pipenv, run pipenv install "Django==6.1.4". For uv, run uv add "Django>=6.1.4" and commit the updated lock file.
If you cannot upgrade, set editable=False on every RasterField and remove it from ModelForms and the admin. That closes the default form path, but a direct assignment of an untrusted dict or JSON string to a RasterField still reaches GDALRaster. Wrap trusted values in GDALRaster and validate untrusted input before assignment.
For CVE-2026-132092, avoid __range with more than two values and __in with a bilateral transform, and remove percent signs from column aliases and key transforms. These are limits on exposure, not a fix. Django 5.1, 5.0 and 4.2 are unsupported; upgrade to 5.2.20 or later.
What is the root cause?
Django4Shell exists because RasterField validates its value only when a query uses it as a lookup, not when a form assigns it to a model instance. The assignment path passes a raw JSON string to GDALRaster, and GDAL writes a file before the model is saved. Mohammed Fathy of Robusta Technology Group reported the flaw and published the analysis as Django4Shell; Django credits Cristian Panaro for CVE-2026-132092.
GeoDjango's RasterField stores a GDALRaster lazily. contribute_to_class attaches a SpatialProxy whose load function is gdal.GDALRaster. In Django 6.1.3, the proxy's __set__ accepts None, str, dict or a GDALRaster and stores the value without validation:
if gtype == "RASTER" and (
value is None or isinstance(value, (str, dict, self._klass))
):
pass
# ...
instance.__dict__[self.field.attname] = value
Those lines are django/contrib/gis/db/models/proxy.py at lines 66 to 88, at tag 6.1.3. RasterField has no formfield() override, so it inherits Field.formfield(), which returns a plain forms.CharField. The GIS admin mixin checks isinstance(db_field, models.GeometryField), and RasterField is a sibling, not a subclass. A ModelForm therefore accepts the field as text.
When the form validates, ModelForm._post_clean() calls instance.full_clean(), which reads every field with getattr. The read goes through SpatialProxy.__get__ and calls GDALRaster on the stored string:
geo_obj = self._load_func(geo_value)
# ...
setattr(instance, self.field.attname, geo_obj)
Those lines are lines 49 and 52 of the same file. GDALRaster.__init__ runs _preprocess_input, which turns a JSON string into a dict. The dict branch sets _write = 1, builds Driver(ds_input.get("driver", "MEM")), and calls capi.create_ds with ds_input["name"]; it then writes each band's data:
elif isinstance(ds_input, dict):
self._write = 1
driver = Driver(ds_input.get("driver", "MEM"))
# ...
self._ptr = capi.create_ds(
driver._ptr,
force_bytes(ds_input.get("name", "")),
# ...
)
Those lines are django/contrib/gis/gdal/raster/source.py at lines 131 to 171, at tag 6.1.3. The EHdr driver writes the band bytes to the name, so the name is the file path and the band data is the content. Nothing in the assignment path calls check_raster_lookup_value, the guard added for CVE-2026-87890.
CVE-2026-15307 fixed the spatial lookup path in August 2026. CVE-2026-87890 fixed a byte-value bypass in October 2026. Both guards sit on the lookup path. Django4Shell is the assignment path that the earlier fixes did not cover.
CVE-2026-132092 is a separate root cause in the ORM's lookup compiler. Range.get_rhs_op formatted BETWEEN %s AND %s with the first two right-hand values and ignored any extras. batch_process_rhs paired SQL fragments and parameters without checking that the two lists had the same length.
A percent sign in a column alias or key transform changed how the SQL string was formatted, so a bound parameter could be read as SQL. The __in variant needed a bilateral transform that compiled to a parameter-less IS NULL.
def get_rhs_op(self, connection, rhs):
return "BETWEEN %s AND %s" % (rhs[0], rhs[1])
Those lines are django/db/models/lookups.py at lines 661 and 662, at tag 6.1.3.
How is it exploited?
Django4Shell is exploited by a staff user who submits a crafted raster value through a form that the application exposes. The write happens during validation, before any model save.
- Sign in with a staff account that can add or change a model with a RasterField in the admin or a ModelForm.
- Submit the form with a JSON raster in the field. Set
drivertoEHdr,nameto a writable path such assitecustomize.pyin the project directory, and put Python source bytes inbands[0].data. - The form calls
full_clean(), which reads the field and callsGDALRasteron the JSON. - GDAL creates the file at
nameand writes the band data. The write completes inside form validation, before the model is saved. - The next Python process start imports
sitecustomize.pyfrom the working directory or anothersys.pathentry, and the payload runs as the web user.
The researcher published this payload structure on django4shell.com. This array is trimmed from that example and spells "import " in ASCII:
{
"driver": "EHdr",
"name": "/app/sitecustomize.py",
"width": 64,
"height": 1,
"srid": 4326,
"nr_of_bands": 1,
"datatype": 1,
"origin": [0, 0],
"scale": [1, -1],
"bands": [{"data": [105, 109, 112, 111, 114, 116, 32]}]
}
No public exploitation in the wild is reported. CISA's Vulnrichment block records Exploitation: none as of 2026-12-02.
For CVE-2026-132092, the attacker needs an application that builds one of the affected queries from attacker-controlled values. A range lookup with three values or an in lookup with a bilateral transform can reach the flaw. A percent sign in an alias or key transform then lets a value escape into SQL.
The application's query shape decides whether the flaw is reachable. A stock Django application that does not use those constructs is not exposed.
How does the attack flow?
A staff form submission reaches GDAL's file writer before the model is saved, and the next Python start runs the written file.
What can an attacker do?
An attacker with a staff account can write arbitrary bytes to any path the Django process can write, and can execute code as that user when Python next starts. The strongest demonstrated outcome is code execution, not only a file write.
For Django4Shell, the attacker can:
- Overwrite application source, templates or configuration.
- Write
sitecustomize.pyor a.pthfile into a directory onsys.path. - Read secrets and environment variables once code runs.
- Pivot to the host or network with the web user's permissions.
The conditions are:
- Staff authentication.
- A RasterField model exposed through a ModelForm, the admin or a writable serializer.
- GDAL with the EHdr driver.
- A writable target path.
- A Python process start after the write.
The researcher says that three of the four conditions beyond staff authentication are met by default. No database write is needed for the file write.
For CVE-2026-132092, the attacker can read or change data the database user can access. The impact depends on the query and the database privileges. The CVE record scores it 9.8 because the vector assumes no privileges and no user interaction, but the application must use the affected query shape. The flaw is in the ORM, not in GeoDjango, and it affects any Django application that builds the affected lookup.
Why does the fix work?
The fix removes the default form path, rejects non-memory drivers on assignment, and makes the lookup compiler enforce the number of range values and parameters.
This is the core of the CVE-2026-124827 patch:
+ def __init__(self, *args, **kwargs):
+ kwargs.setdefault("editable", False)
+ super().__init__(*args, **kwargs)
# ...
- setattr(cls, self.attname, SpatialProxy(gdal.GDALRaster, self))
+ setattr(
+ cls,
+ self.attname,
+ SpatialProxy(gdal.GDALRaster, self, self.init_raster),
+ )
+
+ def init_raster(self, ds_input):
+ """Hook to reject dict values with out-of-memory drivers."""
+ value = gdal.GDALRaster._preprocess_input(ds_input)
+ 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)
editable=False keeps RasterField out of auto-generated ModelForms and the admin unless the developer opts in. init_raster preprocesses the value and rejects any dict whose driver is not MEM or None, so a raw JSON string with EHdr cannot reach GDALRaster through assignment.
A developer can still use another driver by wrapping the value in GDALRaster, which marks it trusted. The exception only limits file writes; the advisory says SSRF is still possible, so validate untrusted input.
This is the core of the CVE-2026-132092 patch:
- for sql, param in zip(*pre_processed)
+ for sql, param in zip(*pre_processed, strict=True)
# ...
- return "BETWEEN %s AND %s" % (rhs[0], rhs[1])
+ start, end = rhs
+ return "BETWEEN %s AND %s" % (start, end)
The range lookup now fails if it receives more than two values, and the strict zip fails if the SQL fragments and parameters do not have the same length. A surplus parameter can no longer shift into the SQL text.
For the reported dict and JSON assignment path, the fix is complete: the assignment path now rejects non-MEM dicts, and the default form path is closed. For SSRF, it is not complete: Django says assignment of untrusted input can still make network requests. For the SQL injection, the fix closes the reported range and in paths; the advisory does not claim it covers every custom lookup or transform.
How do I check if I was compromised?
Start with the files the exploit writes, then the requests that write them. No indicators are published for this campaign.
Use /opt/app as an example; substitute your own deployment root.
find /opt/app -name sitecustomize.py -o -name "*.pth" | head -50
Compare each hit with the repository and the base image. A sitecustomize.py in the project working directory, or a .pth file in site-packages that is not part of a package, is a lead to inspect.
python -c "import site,sys; print('\n'.join(sys.path)); print(site.getsitepackages())"
This prints the directories a sitecustomize.py or .pth file would be imported from. Check each writable directory for files created around the suspected time.
grep -Ei 'POST /admin/[^ ]+/(add|change)/' /var/log/nginx/access.log | tail -50
A POST to a RasterField model's admin add or change view is a lead, not proof. Request bodies are usually not logged. If the proxy logs them, look for "driver" and "EHdr" in the body.
grep -R "EHdr" /var/log/ 2>/dev/null | head
This is a broad search, and a hit is a lead. Also check for outbound connections from the Django process, because assignment of untrusted input can still cause SSRF.
No indicators are published for this issue. A failed attempt may leave no trace, and an attacker who deleted the file may leave only the request log.
Timeline
- 2026-08-04: Django fixed CVE-2026-15307, the first GeoDjango spatial-lookup file-write flaw.
- 2026-10-06: Django fixed CVE-2026-87890, an incomplete fix that left a byte-value SSRF path.
- 2026-12-02: Django released 6.1.4, 6.0.11 and 5.2.20 and published the seven CVE records.
- 2026-12-02: The researcher published django4shell.com, and CISA KEV catalog 2026.11.30 did not list CVE-2026-124827 or CVE-2026-132092. No in-the-wild exploitation was reported.
FAQ
- Is Django4Shell exploited in the wild? No public report existed as of 2026-12-02. Neither CVE is in CISA KEV, and Django's advisory does not mention exploitation.
- Do I need PostGIS to be affected by the RCE? RasterField is implemented only on PostGIS, but the file write happens during form validation, before a database write. The researcher says the form path needs no PostGIS connection and no database table.
- Is CVE-2026-132092 as severe as the RCE? It is CVSS v3.1 9.8 Critical in the CVE record. It needs an application query with a range lookup of more than two values or an in lookup with a bilateral transform. It also needs a percent sign in an alias or key transform. The RCE needs a staff account and a RasterField form.
- Does upgrading fix both? Yes. Django 6.1.4, 6.0.11 and 5.2.20 contain both fixes. The 5.2.20 release is the LTS fix.
- What if I cannot upgrade? Set
editable=Falseon RasterField models and remove them from ModelForms and the admin; this closes the default form path but not direct assignment. Avoid the affected lookup shapes for the SQL injection. Upgrade as soon as possible. - Is the fix complete? It closes the file-write path in the assignment route. Django says untrusted assignment can still cause SSRF, so validate input before assigning it to RasterField.
References
- Django security releases, 6.1.4, 6.0.11 and 5.2.20: https://www.djangoproject.com/weblog/2026/dec/02/security-releases/ (checked December 2, 2026)
- CVE-2026-124827 record: https://www.cve.org/CVERecord?id=CVE-2026-124827 (checked December 2, 2026)
- CVE-2026-132092 record: https://www.cve.org/CVERecord?id=CVE-2026-132092 (checked December 2, 2026)
- CVE-2026-115868 record: https://www.cve.org/CVERecord?id=CVE-2026-115868 (checked December 2, 2026)
- CVE-2026-125673 record: https://www.cve.org/CVERecord?id=CVE-2026-125673 (checked December 2, 2026)
- CVE-2026-119642 record: https://www.cve.org/CVERecord?id=CVE-2026-119642 (checked December 2, 2026)
- CVE-2026-127929 record: https://www.cve.org/CVERecord?id=CVE-2026-127929 (checked December 2, 2026)
- CVE-2026-132809 record: https://www.cve.org/CVERecord?id=CVE-2026-132809 (checked December 2, 2026)
- Django patch for CVE-2026-124827, commit a3934abd: https://github.com/django/django/commit/a3934abd4c0d43430efec34d6ae933794df2c2f5 (checked December 2, 2026)
- Django patch for CVE-2026-132092, commit 1eb6104c: https://github.com/django/django/commit/1eb6104c5805d55fca4cd6cf9c715521934d45fc (checked December 2, 2026)
- Django 6.1.3
SpatialProxy,django/contrib/gis/db/models/proxy.py: https://github.com/django/django/blob/6.1.3/django/contrib/gis/db/models/proxy.py (checked December 2, 2026) - Django 6.1.3
RasterField,django/contrib/gis/db/models/fields.py: https://github.com/django/django/blob/6.1.3/django/contrib/gis/db/models/fields.py (checked December 2, 2026) - Django 6.1.3
GDALRaster,django/contrib/gis/gdal/raster/source.py: https://github.com/django/django/blob/6.1.3/django/contrib/gis/gdal/raster/source.py (checked December 2, 2026) - Django 6.1.3
Rangelookup,django/db/models/lookups.py: https://github.com/django/django/blob/6.1.3/django/db/models/lookups.py (checked December 2, 2026) - Robusta Technology Group, Django4Shell advisory: https://django4shell.com/ (checked December 2, 2026)
- Django security release, 2026-08-04: https://www.djangoproject.com/weblog/2026/aug/04/security-releases/ (checked December 2, 2026)
- Django security release, 2026-10-06: https://www.djangoproject.com/weblog/2026/oct/06/security-releases/ (checked December 2, 2026)
- CISA Known Exploited Vulnerabilities catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked December 2, 2026)
Keep reading
