Django4Shell: How to Check for and Fix the Vulnerability

Django4Shell: How to Check for and Fix the Vulnerability

Django released versions 6.1.4, 6.0.11, and 5.2.20 to fix Django4Shell, a GeoDjango vulnerability that can allow files to be written to the server and, depending on the conditions, enable remote code execution. Proof-of-concept details are publicly available, so you should check your version and use of RasterField as soon as possible.

The issue, CVE-2026-124827, affects RasterField, the GeoDjango field for raster data in applications with PostGIS. Before the fix, it could be exposed through the Django admin, ModelForms, or model serializers with write access enabled. In a typical configuration, access usually requires a staff account; an API or form accessible without authentication changes the exposure profile.

1. Check versions and models

  1. Check the version in the live environment, not just in your development environment. Cycode suggests running this command in the application environment:

    python -m django --version

    You can also check the package with pip show django. Repeat the check in the containers and workers that run the application: an old image or a forgotten background process may still be deploying the vulnerable version.

  2. Compare the result with the fixed branch version. Django released 5.2.20, 6.0.11, and 6.1.4. Earlier versions within those branches are affected according to Cycode: 5.2 versions earlier than 5.2.20, 6.0 versions earlier than 6.0.11, and 6.1 versions earlier than 6.1.4. Django did not assess the 5.1, 5.0, and 4.2 branches, which could also be affected.

    BranchFixed version
    Django 6.16.1.4
    Django 6.06.0.11
    Django 5.25.2.20

    If you use an unassessed earlier branch, do not assume it is safe: plan to update to a fixed branch and test the changes before deploying it.

  3. Locate models with RasterField in the repository:

    grep -rn "RasterField" --include=*.py .

    The specific flaw does not affect geometry fields that store shapes such as points or polygons. It concerns RasterField in GeoDjango, used with PostGIS. If the project does not use this field, it is not exposed to Django4Shell through this vector; even so, the same versions fix other flaws, including an SQL injection issue.

  4. Trace each field back to its inputs. Check whether it appears in the admin, a ModelForm, or a serializer that allows writing to the model. Also review which users can submit this data and whether there is a public route. It is not enough for the team to know that the application “uses GeoDjango”: exposure depends on a model declaring RasterField and an input reaching it.

2. Update and validate the change

  1. Install the fix for your branch: Django 5.2.20, 6.0.11, or 6.1.4. If your project is on an earlier branch, Cycode recommends migrating to 5.2.20 or later and testing the update, as it may involve backward-incompatible changes. Do not leave the fix applied only in the repository: it must reach the services and workers that run the application.

  2. Rebuild and redeploy the images that install Django using pip. Cycode recommends rebuilding and deploying them after updating. If Django comes from a distribution package, check for and apply the vendor update when it is published; do not replace this check with the assumption that the package is already fixed.

  3. Test the screens that edit raster data before taking the change to production. The fix makes RasterField non-editable by default. As a result, the field no longer appears in forms generated by the admin or in ModelForms, unless the application explicitly includes it. A legitimate raster upload or editing feature may need adjustments.

  4. Limit explicit editing to controlled inputs. If the application still needs to receive raster data, review how it is validated before being assigned to the field. Django warns that the update does not eliminate the risk of server-side request forgery when untrusted input is assigned to RasterField. Do not restore its default editability without reviewing the data flow and permissions.

  5. Clear potentially affected caches after updating. The versions also fix a cache poisoning issue, but the fix does not invalidate responses that may already be stored.

3. Check for signs of previous activity

  1. Examine application logs and files if the field was exposed before the patch was installed. Cyber Security News recommends looking for unexpected file changes, new processes, and unusual outbound connections. SecurityWeek reports that the flaw could allow writing to accessible paths, modifying code, altering configuration files, or leaving a web shell; the outcome depends on the conditions and system permissions.

  2. Compare files with a known-good build if you suspect exploitation. Lalit Rawat, CISO of Kanerika, recommended checking application files against a trusted version and looking for unexpected startup Python files. Snyk advised rotating credentials accessible to the Django process and rebuilding affected systems from a trusted image if evidence of exploitation is found.

  3. Restrict the web process's access as a complementary measure. InfoWorld reports the recommendation to prevent application processes from accessing sensitive internal services, such as cloud metadata endpoints, and to ensure that code and package directories are not writable by those processes. These measures do not replace updating.

Mistakes to avoid

Do not assume an application is safe without reviewing it just because it does not visibly process raster data: search the models for RasterField and check how it is exposed. Also, do not confuse this flaw with an issue affecting all GeoDjango fields: the sources specifically describe RasterField, not geometry fields.

Do not assume the patch eliminates all risk when assigning raster data. The update fixes the described unauthorized file writing, but Django continues to warn about SSRF if untrusted data is assigned. And do not consider the work complete once the package is updated: forms may behave differently, caches may retain previous responses, and old containers may still be running.

InfoWorld quotes Akshat Tyagi of HFS Research on the teams' first task: “identify which applications use these affected features”, especially when they receive external data. The practical check is straightforward: deployed version, models with RasterField, and every route that can write to them.

Sources: SecurityWeek, InfoWorld, The Hacker News, Cyber Security News, Cycode