Blog

Django4Shell and 6 More Django Flaws: Check Your Project

Updated:

Django4Shell (CVE-2026-124827) lets a crafted raster value write files on a GeoDjango server. Update to Django 6.1.4, 6.0.11 or 5.2.20: the same releases fix six more flaws, including SQL injection. Status: official Django security release of December 2, 2026.

What the December 2026 Django security release fixes

On December 2, 2026 the Django project published three patch releases and listed seven vulnerabilities in its security announcement. Two are rated high, one moderate, four low. Severity below is Django's own rating.

CVEWhat goes wrongDjango ratingWho should care
CVE-2026-124827File write on the server through a RasterField value (Django4Shell)HighGeoDjango with rasters on PostGIS
CVE-2026-132092SQL injection in range and in lookupsHighAliases or key transforms containing %
CVE-2026-115868XSS in truncatechars_html and Truncator.chars(html=True)ModerateTruncated HTML placed inside an attribute
CVE-2026-125673Cache poisoning through . and .. in the request pathLowSites with page caching
CVE-2026-119642Admin list URL lookups leak data through the pk alias of a OneToOneFieldLowAdmin staff users, multi-table inheritance
CVE-2026-127929Admin leaks data through reverse relation lookupsLowAdmin staff users with view permission
CVE-2026-132809Heap buffer overflow in OGRGeometry.wkbLowGeometries larger than 4 GB

Fixed versions are Django 6.1.4, 6.0.11 and 5.2.20 LTS. Django 4.2 LTS left support on April 7, 2026, so it gets nothing this time.

What is Django4Shell and how does it work

RasterField stores raster data, such as satellite tiles or elevation maps, and relies on the GDAL library. A raster can be described as a dictionary or a JSON string that includes a file name and a driver. If a user controlled both the name and a non-default driver, GDAL could write a file to a location the attacker chose. Whether that becomes code execution depends on the driver and on what the web process is allowed to write.

The reason this reaches ordinary pages is a quiet default: for forms, RasterField fell back to a plain text field. So a model with a raster field exposed it in three places without any special setup of the field: the Django admin, a ModelForm and a writable model serializer.

Snyk adds an important detail: the file is written while the form is being validated. No save() and no database row are needed, so a submission that ends with an error on some other field is not harmless.

QuestionWhat sources say
SeverityDjango: high. CVSS differs by outlet: 8.8 (SecurityWeek), 9.0 (The Hacker News)
Login needed?Depends on who can submit the field; Snyk expects a staff account in most deployments
Public exploit detailsSecurityWeek (December 3): proof-of-concept details are public
Attacks in the wildNone reported; Snyk knew of none on December 2
Reported byMohammed Fathy

Step 1: check which Django version is really running

Ask the environment that serves requests. A lock file in the repository, an old image or a forgotten background worker can all disagree.

Installed versionbash
# inside the virtual environment that actually runs the site
python -m django --version

# Docker Compose: ask the running containers, not requirements.txt
docker compose exec web python -m django --version
docker compose exec worker python -m django --version

Anything below 5.2.20 on the 5.2 line, below 6.0.11 on 6.0 or below 6.1.4 on 6.1 needs the update. Include staging servers, cron hosts and one-off management containers in the list.

Step 2: find out whether Django4Shell concerns you

You need all of this at once: django.contrib.gis, a PostGIS database, a model with a raster field and some path where a user's value reaches it. Start with a text search.

Search the code and dependenciesbash
# GeoDjango and raster fields in your own code
grep -rnE "django\.contrib\.gis|RasterField" --include="*.py" .

# the same in installed third-party packages (Django itself is skipped)
grep -rln "RasterField" "$(python -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')" --include="*.py" --exclude-dir=django

# Docker: the packages live inside the container, so search there
docker compose exec web sh -c 'grep -rln "RasterField" "$(python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])")" --include="*.py" --exclude-dir=django'

A search misses fields defined through your own base classes, so also ask Django itself. This snippet walks every registered model:

List raster fields (Django shell)text
# python manage.py shell
from django.apps import apps

for model in apps.get_models():
    for field in model._meta.get_fields():
        if any(c.__name__ == "RasterField" for c in type(field).__mro__):
            print(model._meta.label, field.name, "editable:", field.editable)

Empty output means no model in this project has a raster field. If something is printed, look at every admin class, form, serializer and import script that writes to it. Pay attention to code that assigns request data directly, for example obj.raster = request.POST["raster"]: that is dangerous regardless of any form.

Step 3: check range and in lookups (SQL injection)

CVE-2026-132092 gets less attention than the file write but does not require maps at all. It concerns queries with __range or __in that involve a column alias or a JSON key transform containing a percent sign. Two details narrow it down: for range the lookup had to receive more than two values, and for in a bilateral transform was needed.

Where to lookbash
# range and in lookups
grep -rnE "__(range|in)\b" --include="*.py" .

# names built at run time (calls split across several lines are missed)
grep -rnE "(annotate|alias|aggregate|values|filter|exclude|Q)\(.*\*\*" --include="*.py" .

# bilateral transforms (needed for the __in case) and JSON key transforms
grep -rnE "bilateral *= *True|KeyTransform\(|\bKT\(" --include="*.py" .

# Django 6.x only: warnings from the code your tests actually execute
python -Wa manage.py test

The risky pattern is a name that comes from outside: a report builder that turns query parameters into annotate(**{name: ...}), or a filter that builds a JSON key path from user input. Compare such names against a fixed list instead of passing them through. Django also notes that percent signs in aliases and key transforms have been deprecated since 6.0 and are scheduled for removal in Django 2028, so rename them now.

Step 4: the XSS, cache and admin fixes

Templates and cachingbash
# truncatechars_html and Truncator(...).chars(..., html=True)
grep -rnE "truncatechars_html|Truncator\(" --include="*.html" --include="*.py" .

# page caching affected by the dot-segment bug
grep -rnE "UpdateCacheMiddleware|cache_page|build_absolute_uri" --include="*.py" .
  • truncatechars_html. The problem appears when the text length equals the truncation length and the result lands inside an HTML attribute, such as title or data-*. After updating, still avoid putting truncated HTML into attributes. For plain text there, use {{ value|striptags|truncatechars:80|force_escape }}: without force_escape, a value marked safe is not escaped and a quote can break out of the attribute. HTML entities may then show up escaped twice, which is ugly but harmless.
  • Cache poisoning. Paths with . or .. were normalized, so an unauthenticated visitor could get cached responses served for unintended URLs in some setups. Entries cached before the update are not invalidated.
  • Admin leaks. A staff user with view permission could learn related data by repeating requests with lookup parameters in the query string of the list page. Removing search_fields is not the fix. If you give admin access to clients or contractors, review those permissions while you are at it.
  • OGRGeometry.wkb. Needs geometries over 4 GB on a 64-bit system. Updating is enough.

Step 5: update to Django 6.1.4, 6.0.11 or 5.2.20

Stay on your current feature line for the security update. A jump from 5.2 to 6.x is a separate project: Django 6.0 and 6.1 require Python 3.12 or newer.

pip, Poetry, uvbash
# run ONE line: the one for your feature line and your tool
pip install "Django==5.2.20"     # 5.2 LTS
# pip install "Django==6.0.11"   # if you are on 6.0
# pip install "Django==6.1.4"    # if you are on 6.1

# Poetry, example for 5.2 LTS
# poetry add "django@~5.2.20"

# uv, example for 5.2 LTS (updates the lock file and the environment)
# uv add "django>=5.2.20,<6.0"

Update the file your deployment reads (requirements.txt, poetry.lock, uv.lock), run the tests, then run python manage.py makemigrations --check --dry-run to see whether anything in your models now differs. Restart every long-running process: a Python process keeps the old code in memory.

Restart and verifybash
# systemd
sudo systemctl restart gunicorn      # or uwsgi, daphne, uvicorn
sudo systemctl restart celery        # workers import your models too

# Docker Compose: rebuild the image, a changed requirements.txt alone does nothing
docker compose build --no-cache web worker
docker compose up -d web worker
docker compose exec web python -m django --version

Then clear page caches, including the CDN in front of the site if it stores HTML. Be careful here: Django's built-in RedisCache.clear() flushes the whole Redis database. If your Celery queue or other keys share that database, they are deleted too, and clearing Memcached empties the whole server. Sessions kept in the cache disappear, so users get logged out.

Check, then clear Django cachesbash
# 1. look first: where does each cache live? (the output may contain a password)
python manage.py shell -c "from django.conf import settings; [print(k, v.get('BACKEND'), v.get('LOCATION')) for k, v in settings.CACHES.items()]"

# 2. only if nothing else lives in that Redis database or Memcached server
python manage.py shell -c "from django.core.cache import caches; [c.clear() for c in caches.all()]"

# with Docker, run the same inside the container
# docker compose exec web python manage.py shell -c "..."

If the database is shared, do not flush it. Set a new KEY_PREFIX for that cache in CACHES and restart: old entries are simply no longer read (cached sessions included). The local-memory cache belongs to each process, so a command in the shell does not touch it; restarting the web processes does.

What changes in your code after the update

RasterField is no longer editable by default

RasterField now has editable=False, so it disappears from admin forms and every ModelForm that picked it up automatically. If editors suddenly report a missing input, this is the reason.

The update can also break code. A non-editable field listed by name in Meta.fields raises FieldError, and so does naming it in the admin's fields or fieldsets. Adding the name to a list is therefore not a way to bring it back: set editable=True on the model field or declare a form field of your own, and only for trusted users. In Django REST Framework a ModelSerializer turns a non-editable field into a read-only one, so your API will start silently ignoring rasters that clients send.

build_absolute_uri() keeps dot segments

As part of the cache fix, request.build_absolute_uri() called without a location now preserves . and .. segments of the request path. If your code or tests relied on the normalized form, adjust them.

Dictionaries with other GDAL drivers are rejected

Assigning a dictionary or JSON string that names a non-default driver now raises GDALException. The default is the in-memory MEM driver. If your own pipeline needs another driver, wrap the value in GDALRaster, which marks it as trusted:

Trusted data onlytext
from django.contrib.gis.gdal import GDALRaster

# allowed only for a definition that YOUR code produced, never for request data
tile.raster = GDALRaster(definition_from_your_pipeline)
tile.save()

If you cannot update today

Updating is the fix, and we found no official workaround. These measures only reduce exposure for a day or two:

  • Remove raster fields from public forms and API serializers.
  • Mark the field non-editable, a measure suggested by Cycode.
  • Limit the admin to trusted people and, if possible, to your VPN or office addresses.
  • Make code and site-packages directories read-only for the web process.
  • Block the web server's access to the cloud metadata endpoint, which limits SSRF damage.
Stopgaptext
# models.py, temporary measure until you can upgrade
from django.contrib.gis.db import models

class Tile(models.Model):
    raster = models.RasterField(editable=False)  # leaves ModelForm and the admin form

The stopgap has limits. It does not protect form or serializer fields you declared by hand, or code that assigns request data to the field directly, and forms that list the field by name will raise the same FieldError. None of this covers the SQL injection or the other fixes. For the login page of the admin itself, our guide to website admin panels explains how to reach and protect it.

Check for traces of an attack

Do this if a raster field was reachable by people you do not fully trust. The published attack chain drops files that Python executes at startup, or web shells in static directories.

Unexpected filesbash
# startup files Python runs on its own
find "$(python -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')" . \
  \( -name "sitecustomize.py" -o -name "usercustomize.py" -o -name "*.pth" \) -ls

# recently changed files; move the date back as far as your exposure goes
find . -type f -newermt "2026-11-01" \( -name "*.py" -o -name "*.pth" -o -name "*.php" -o -name "*.sh" \) -ls

# difference from the repository, including ignored folders such as media
git status --porcelain --untracked-files=all --ignored

# Docker: the files live in the container, so look there too
docker compose exec web sh -c 'find / -xdev \( -name "sitecustomize.py" -o -name "*.pth" \) -ls'
docker compose exec worker sh -c 'find / -xdev \( -name "sitecustomize.py" -o -name "*.pth" \) -ls'

Many .pth files are legitimate (editable installs and setuptools create them), so open each one and match it to a package you know. Snyk also suggests reviewing POST requests to the admin and to raster forms for ../ sequences, /vsi prefixes and the EHdr driver name. Standard web server logs do not store request bodies, so finding nothing there proves little. An empty result of these commands does not prove there was no break-in either: they look only for the obvious traces.

If you do find something, take the server offline, rebuild it from a clean image and rotate every secret the process could read. The order of rotation is the same as in our server check after the React2Keys campaign. For Django add one more item: change SECRET_KEY, and do not leave the compromised value in SECRET_KEY_FALLBACKS.

Django security update checklist

#ActionDone when
1List every environment that runs DjangoWeb, workers, cron, staging are on the list
2Search for raster fieldsYou know who can write to each one
3Review dynamic aliases and key lookupsNo user text becomes a query name
4Install the patch release and run testspython -m django --version shows it
5Restart processes and rebuild imagesRunning containers report the new version
6Clear page and CDN cachesOld cached responses are gone
7Check files and logsNo unexplained files for the whole exposure period

Finally, subscribe to the Django security process announcements and let a dependency bot open pull requests for patch releases. Review them before they merge: our guide to supply chain attacks shows why automatic updates need a short delay and a human look.

Frequently asked questions

What is Django4Shell?

Django4Shell is the informal name of CVE-2026-124827, fixed on December 2, 2026. A crafted raster definition assigned to a GeoDjango RasterField on PostGIS could make the GDAL library write a file on the server, which in some setups leads to remote code execution. Django itself rates it “high”.

Which Django versions fix it?

Django 6.1.4, 6.0.11 and 5.2.20, all released on December 2, 2026. The same releases fix six other vulnerabilities, so update even if you do not use GeoDjango at all.

Am I affected if I do not use GeoDjango?

Not by Django4Shell itself: it needs a RasterField, which exists only on PostGIS. But the same releases fix an SQL injection in range and in lookups, an XSS in truncatechars_html, a cache poisoning issue and two admin information leaks that have nothing to do with maps.

Does an attacker need to log in?

It depends on who can submit your form or API. Django says the path was reachable by default through the admin, ModelForms and writable model serializers. Snyk estimates that in most deployments a staff or admin account is needed. If a public form or endpoint writes to a RasterField, do not count on a login.

Is it being exploited?

We found no report of real attacks as of December 4, 2026. Snyk wrote on December 2 that it was not aware of any. SecurityWeek reported on December 3 that proof-of-concept details are public, so treat the window as short.

Does it affect Django REST Framework?

It can. A writable model serializer that includes a RasterField is one of the paths Django names. The flaw is in Django, so updating Django is the fix; also check which serializers expose raster fields and who may call them.

What about Django 4.2 or 5.1?

These series are no longer supported (4.2 LTS ended on April 7, 2026) and receive no patch. Django’s post names only 6.1, 6.0, 5.2 and main. Snyk and Cycode advise treating older versions as at risk and moving to 5.2.20 or newer.