Django4Shell
CIA Risk Posture & Executive Assurance
Planted Python startup code reads SECRET_KEY, database passwords, and cloud keys on worker boot; CVE-2026-132092 also patches a High-severity ORM SQL injection.
Staff users or writable API tokens on GeoDjango RasterField models can write sitecustomize.py or .pth files during validation—breaking multi-tenant isolation.
Arbitrary file writes can corrupt app configs, while CVE-2026-125673 dot-segment cache poisoning and CVE-2026-132809 OGRGeometry heap overflows impact availability.
RasterField or run EOL Django 4.2 / 5.0 / 5.1?
Django4Shell affects GeoDjango on PostGIS when a RasterField is reachable via Django Admin, a ModelForm, or a writable serializer—while the other 6 fixes (including SQLi CVE-2026-132092) apply to broader Django apps. EOL branches (4.2, 5.0, 5.1) receive no security patch.
Because CVE-2026-124827 is an incomplete patch lineage from August’s CVE-2026-15307 and writes files before model.save(), revoking a contractor or phished staff login does not remove a planted sitecustomize.py or .pth backdoor.
Django4Shell (CVE-2026-124827) is a server-side arbitrary file-write and remote code execution vulnerability in GeoDjango’s django.contrib.gis.db.models.RasterField, patched on December 2, 2026 in Django 6.1.4, 6.0.11, and 5.2.20 alongside six additional security vulnerabilities.
Reported by Mohamed K. Fathy of Robusta Technology Group
(django4shell.com ↗,
The Hacker News ↗)
and scored CVSS v3.1 8.8 / v4.0 8.7 (High) by the Django Software Foundation CNA (9.0 researcher rating),
CVE-2026-124827 is the fourth GeoDjango raster fix of 2026—closing an incomplete fix chain after February’s CVE-2026-1207 (actively scanned within weeks per CrowdSec), August’s CVE-2026-15307 (spatial lookup file write), and October’s CVE-2026-87890 (GDAL Virtual Raster SSRF).
How validation becomes RCE before model.save():
Because RasterField (implemented on PostGIS; standard geometry fields like points and polygons are unaffected) fell back to a plain CharField form widget, any model with a RasterField registered in Django Admin, exposed in a ModelForm, or wired into a writable REST serializer accepted raw JSON/dict raster definitions by default. Submitting a crafted JSON raster body with an attacker-controlled name path and a non-default GDAL driver such as EHdr (shipped in every standard apt, yum, Homebrew, and conda GDAL build) forces GDAL to write an arbitrary file during form/serializer validation—before model.save() or any database transaction runs.
From file write to persistent shell:
As detailed in MATT Research’s analysis ↗,
when the web worker’s current working directory (typically on sys.path) or virtual environment is writable, writing sitecustomize.py, usercustomize.py, or a .pth file in site-packages causes Python to execute the attacker’s code automatically on the next Gunicorn/uWSGI worker fork, manage.py cron job, subprocess spawn, or reload. That turns a phished staff account, a tenant-scoped customer admin in a multi-tenant GIS SaaS, a leaked partner API token on a writable serializer, or a departing contractor into full server compromise.
Six Companion Fixes in 6.1.4 / 6.0.11 / 5.2.20:
Even Django deployments without GeoDjango should upgrade for the December 2 release’s six other fixes
(Django Security Advisory ↗),
led by High-severity SQL injection in __range and __in lookups involving % in column aliases or key transforms (CVE-2026-132092), Moderate XSS in truncatechars_html inside HTML attributes (CVE-2026-115868), and dot-segment cache poisoning in HttpRequest.build_absolute_uri() (CVE-2026-125673).
Why it’s a risk
If an application uses RasterField on PostGIS, three of the four exploit preconditions—default Admin/ModelForm exposure, GDAL’s built-in EHdr file driver, and a writable worker CWD or site-packages—are typically met out of the box. Only staff-level authentication or a writable API serializer token is needed to plant startup code or web shells without touching the database.
How to recognize it (Versions, Logs & Persistence IoCs)
-
Vulnerable versions: Django
6.1 < 6.1.4,6.0 < 6.0.11, and5.2 < 5.2.20. End-of-life branches (5.1,5.0,4.2and older) receive no upstream patch. -
Codebase exposure check: Models importing
django.contrib.gis.db.models.RasterFieldwithouteditable=Falseor explicit exclusion inModelAdmin,ModelForm, or Django REST Framework serializers. -
Host & audit indicators: Unexpected
sitecustomize.pyorusercustomize.pyonsys.path, newly created*.pthfiles insidesite-packagessince August 2026, or suspicious POSTs /django_admin_logentries on raster models.
How to mitigate it
-
Upgrade immediately to Dec 2 releases: Update to Django
6.1.4,6.0.11, or5.2.20(which setRasterField(editable=False)by default and raiseGDALExceptionon non-default dict/JSON drivers), redeploy workers, and flush page caches forCVE-2026-125673. -
Emergency workaround if upgrade waits: Set
editable=Falseon everyRasterFieldand add it toexclude/read_only_fieldsacross allModelAdmin,ModelForm, and DRF serializer classes. -
Defense-in-depth & persistence hunt: Mount application code, virtualenvs, and
site-packagesread-only to the web process, disable unused GDAL drivers viaGDAL_SKIP, and enforce MFA on all staff logins.Show persistence hunt & hardening CLI Hide persistence hunt & hardening CLI
# 1. Check installed Django version (must be >= 6.1.4, 6.0.11, or 5.2.20) python -m django --version # 2. Locate any GeoDjango RasterField definitions in your app code grep -rn "RasterField" --include="*.py" --exclude-dir=".venv" --exclude-dir="venv" . # 3. Check for planted sitecustomize.py / usercustomize.py (compare any non-None path against base OS image) python -c "import importlib.util as u; print(u.find_spec('sitecustomize'), u.find_spec('usercustomize'))" # 4. Hunt rogue .pth startup files modified since August 2026 python -c "import site, pathlib, time; [print(p) for d in site.getsitepackages() for p in pathlib.Path(d).glob('*.pth') if p.stat().st_mtime > 1754265600]"# Upgrade within your supported major/minor track (6.1.4, 6.0.11, or 5.2.20) pip install --upgrade "Django~=6.1.4" # or "Django~=6.0.11" / "Django~=5.2.20" # Restrict unused GDAL file-writing drivers in service environment export GDAL_SKIP="EHdr ENVI PAux MFF HFA NITF" # Clear Django cache after upgrading (required for CVE-2026-125673 dot-segment cache poisoning) python manage.py shell -c "from django.core.cache import cache; cache.clear()"
- Relying on DB errors or read-only DB roles: GDAL writes the attacker’s file during form/serializer validation before
model.save()or any SQL query executes—even a failed validation request can drop the payload. - Deactivating a staff user without checking
.pth/sitecustomize.py: A planted startup file in CWD orsite-packagespersists across restarts long after the staff account or API token is revoked; rebuild from a clean container image. - Wrapping untrusted input in
GDALRaster(): In patched Django, wrapping input inGDALRasterexplicitly marks it as trusted; Django warns that untrustedRasterFieldinput can still trigger SSRF unless strictly validated first. - Upgrading without clearing page caches: Existing responses poisoned via
CVE-2026-125673dot-segment paths (./..inbuild_absolute_uri()) are not invalidated automatically when Django upgrades.
| CVE Identifier | Severity | Fixed In (Dec 2) | Vulnerability Class & Exploit Preconditions |
|---|---|---|---|
CVE-2026-124827 ↗Django4Shell |
8.8 High (v3.1, Django) 9.0 Researcher |
6.1.4 · 6.0.11 · 5.2.20 | GeoDjango RasterField Arbitrary File-Write RCE: Assigning a JSON/dict raster with user-controlled name + non-default GDAL driver (EHdr) via Admin, ModelForm, or writable serializer writes arbitrary files (sitecustomize.py, .pth) during validation. |
| CVE-2026-132092 ↗ | High (Django Policy) | 6.1.4 · 6.0.11 · 5.2.20 | ORM SQL Injection in range & in Lookups: Queries using column aliases or key transforms containing % were vulnerable to SQLi when __range passed >2 RHS values or __in used a bilateral transform. |
| CVE-2026-115868 ↗ | Moderate (Django) | 6.1.4 · 6.0.11 · 5.2.20 | Cross-Site Scripting in truncatechars_html: truncatechars_html and Truncator.chars(html=True) allowed attribute-context XSS when input text length matched the truncation length. |
| CVE-2026-125673 ↗ | Low (Django) | 6.1.4 · 6.0.11 · 5.2.20 | Web Cache Poisoning via Dot Segments: HttpRequest.build_absolute_uri() mis-normalized . and .. path segments in UpdateCacheMiddleware / @cache_page, allowing unauthenticated cache poisoning. Flush caches post-upgrade. |
| CVE-2026-119642 ↗ | Low (Django) | 6.1.4 · 6.0.11 · 5.2.20 | Admin Changelist Leakage via pk Alias: Staff users with view permission on models using a custom OneToOneField primary key (including multi-table inheritance by default) could enumerate related data via querystring lookups. |
| CVE-2026-127929 ↗ | Low (Django) | 6.1.4 · 6.0.11 · 5.2.20 | Admin Changelist Leakage via Reverse Relations: Regression from Django 5.0.3 (reported by OpenAI) allowing staff users with view permission to enumerate related model values via reverse-relation querystring searches. |
| CVE-2026-132809 ↗ | Low (Django) | 6.1.4 · 6.0.11 · 5.2.20 | Heap Buffer Overflow in OGRGeometry.wkb: Undersized buffer allocation on 64-bit platforms for geometries larger than 4GB (also affecting hex, geos, and pickling). |