Directory Traversal Vulnerability in Python-Django: CVE-2021-31542

python-django Updated 02 Oct 2025

Summary

04/05/2021
N/A
Yes i
High
7.5

UBUNTU-CVE-2021-31542: In Django 2.2 before 2.2.21, 3.1 before 3.1.9, and 3.2 before 3.2.1, MultiPartParser, UploadedFile, and FieldFile allowed directory traversal via uploaded files with suitably crafted file names. Affects python-django versions < 1.6.11-0ubuntu1.3+esm3. Fixed in 1.6.11-0ubuntu1.3+esm3. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Python-Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It is widely used for building web applications and provides a robust set of features for developers. However, certain versions of Django are vulnerable to a directory traversal attack, which can allow unauthorized access to the file system through crafted file names.

Vulnerability Detail

The vulnerability, identified as CVE-2021-31542, affects Django versions 2.2 before 2.2.21, 3.1 before 3.1.9, and 3.2 before 3.2.1. It allows attackers to exploit the MultiPartParser, UploadedFile, and FieldFile components to perform directory traversal via uploaded files with specially crafted file names. This can lead to unauthorized file access, potentially exposing sensitive data or system files.

How To Fix

Minimum fixed version

1.6.11-0ubuntu1.3+esm3

This is the first release that contains the fix.

sudo apt-get install --only-upgrade python-django

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, users can implement file name validation on the server-side to prevent directory traversal attacks. Ensure that uploaded file names do not contain any path traversal characters such as '../'.

Conclusion

CVE-2021-31542 is a significant vulnerability in certain versions of Python-Django that can lead to directory traversal attacks. It is crucial for users to update their Django installations to the patched versions to mitigate this risk. Additionally, implementing server-side validation for file uploads can serve as a temporary workaround.

See every vulnerability recorded for python-django →

Share this vulnerability

FAQ

CVE-2021-31542 is a vulnerability in Django that allows directory traversal via uploaded files with crafted file names.

Django versions 2.2 before 2.2.21, 3.1 before 3.1.9, and 3.2 before 3.2.1 are affected by this vulnerability.

Exploitation of this vulnerability can lead to unauthorized access to sensitive files on the server, potentially compromising the application and its data.

You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. Check your application against this vulnerability using the Vulert playground at Vulert Scanner.

The CVSS score of CVE-2021-31542 is 7.5, indicating a high severity level.

Related vulnerabilities

Recent vulnerabilities recorded for python-django.

How To Fix

Minimum fixed version

1.6.11-0ubuntu1.3+esm3

This is the first release that contains the fix.

sudo apt-get install --only-upgrade python-django

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback