Security

Django Fixes High-Severity Security Flaws Including Potential Remote Code Execution Risk

The Django team has released Django 6.1.4, 6.0.11, and 5.2.20 to fix seven security issues, including two rated high severity. Here is what was fixed and what you should do.

Django security releases fixing high-severity vulnerabilities
Django 6.1.4, 6.0.11, and 5.2.20 fix seven security issues.

The Django team has issued security releases for three versions: 6.1.4, 6.0.11, and 5.2.20. They fix seven problems, and the team asks everyone to upgrade as soon as possible.

Two of the problems are rated high severity. One could, in some setups, lead to remote code execution, which means an attacker running their own code on your server.

Which versions are affected?

The issues affect Django main (the development branch), 6.1, 6.0, and 5.2. Patches are in the three new releases:

  • Django 6.1 users: upgrade to 6.1.4.
  • Django 6.0 users: upgrade to 6.0.11.
  • Django 5.2 users: upgrade to 5.2.20.

You can get them from the Django download page. The upgrade guide explains how to move between versions safely.

The high-severity issues

1. RasterField file write that could lead to code execution (CVE-2026-124827)

RasterField is a Django GIS field for raster data, which is map-like image data. It only exists on PostGIS, a map-data add-on for the PostgreSQL database.

If an app let a user control the name of a raster and choose a non-default driver, the underlying GDAL library could write a file to a place the attacker picked. Depending on the driver, that could allow remote code execution.

The risk was easy to reach. RasterField falls back to a plain text form field, so models using it in the admin, in ModelForms, or in writable serializers were reachable by default.

What changed:

  • RasterField is now editable=False by default, so a ModelForm leaves it out unless you add it.
  • Assigning a dict or JSON string that names a non-default driver now raises a GDALException.
  • To use other drivers, wrap the definition in GDALRaster to show you trust the value.

One limit: this only stops server-side file writes. Server-side request forgery, where the server is tricked into calling other addresses, is still possible if untrusted input goes into RasterField. Django's GIS documentation has security notes for rasters, and you should validate input before accepting it. Geometry fields were not affected.

2. Possible SQL injection in range and in lookups (CVE-2026-132092)

SQL injection is when an attacker sneaks database commands into a query. Django's range and in lookups could be affected in queries that use aliases or key transforms containing percent signs.

  • The __range case needed the code to wrongly pass more than two values on the right-hand side.
  • The __in case needed a bilateral transform, a transform applied to both sides of the comparison.

The range lookup now requires exactly two values. Django also notes that percent signs in column aliases and key transforms were already deprecated in Django 6.0 and are planned for removal in 2028.

The other five fixes

Moderate severity

  • XSS in truncatechars_html (CVE-2026-115868): the truncatechars_html template filter, and Truncator.chars() with html=True, could allow cross-site scripting (XSS), where an attacker's script runs in a visitor's browser. It happened for certain inputs whose text length matched the cut-off length when the result was placed in an HTML attribute.

Low severity

  • Cache poisoning via dot segments (CVE-2026-125673): build_absolute_uri() wrongly cleaned up paths with . or .. parts. In some setups, this could let an unauthenticated attacker cause cached pages to be served for the wrong URLs. It affects UpdateCacheMiddleware and cache_page(). Old cached pages are not cleared by the fix, so clear any caches that may be affected. See Django's cache documentation.
  • Admin leak via the pk alias (CVE-2026-119642): staff users with view permission could read data from models with a custom OneToOneField primary key, by using pk in the URL query and searching repeatedly. This needs good knowledge of the related model's fields. Models using multi-table inheritance were affected by default.
  • Admin leak via reverse relations (CVE-2026-127929): staff users with view permission could also guess values by changing the URL query, if they knew the related model names. It is a case of an older issue, CVE-2010-4534, that came back in Django 5.0.3. The Django team credits OpenAI for reporting it.
  • Buffer overflow in OGRGeometry.wkb (CVE-2026-132809): for shapes larger than 4GB on 64-bit systems, the buffer was too small. This could cause crashes or undefined behavior. It also affected the hex and geos properties and pickling.

What should you do?

  1. Check your Django version, and upgrade to 6.1.4, 6.0.11, or 5.2.20.
  2. Check whether you use RasterField and, if so, who can write to it.
  3. Search your code for __range lookups with extra values and for percent signs in aliases.
  4. Clear page caches that use cache_page() or the cache middleware.
  5. Review who has admin staff access.

Report any new Django security problem by private email to [email protected], and not through public places like the bug tracker or forum. Django's security policy explains the process, and the archive of security issues lists past fixes.

What It Means for Developers

Most Django sites are not affected by every issue here, but all supported versions got patches, so upgrading is the safest move.

What It Means for Backend Developers

  • If you use GIS and PostGIS, check any model with RasterField, and never accept raster definitions from untrusted users.
  • Review raw SQL and custom lookups that use aliases or key transforms with percent signs, and make sure range always gets exactly two values.
  • If you use truncatechars_html in templates, upgrade and check where its output lands, especially inside HTML attributes.
  • If your admin has custom OneToOneField primary keys or many related models, upgrade to close the data leaks.

What It Means for DevOps Engineers

  • Roll the patched version through your build and deploy process, and pin it in your requirements file.
  • After upgrading, flush caches that may hold wrongly keyed pages. The fix does not remove old cached responses.
  • For another recent Python supply chain story, read our report on the PyPI malware attack on Microsoft Agent Framework.
  • To see how a website was attacked through injected scripts, read about the Optimizely security incident.

Bottom line

Django has patched seven security issues across 6.1, 6.0, and 5.2. Two are high severity: a RasterField flaw that could allow code execution in some setups, and a SQL injection bug in range and in lookups.

Upgrade to 6.1.4, 6.0.11, or 5.2.20, clear affected caches, and review any code that handles raster data or uses the lookups mentioned above.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author