Directory Traversal Vulnerability in python-django
Summary
CVE-2009-2659: The Admin media handler in core/servers/basehttp.py in Django 1.0 and 0.96 does not properly map URL requests to expected "static media files," which allows remote attackers to conduct directory traversal attacks and rea... Affects python-django versions < 1.1-1. Fixed in 1.1-1. How to fix ↓
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.
No signup required · Results in about 60 seconds
Background
python-django is a popular web framework for building web applications using the Python programming language. It provides a high-level API for handling web requests and generating dynamic web content. The vulnerability in python-django allows remote attackers to conduct directory traversal attacks and read arbitrary files by exploiting a flaw in the Admin media handler.
Vulnerability Detail
The Admin media handler in python-django does not properly map URL requests to expected "static media files." This allows an attacker to manipulate the URL and traverse directories to access files outside the intended scope. By crafting a malicious URL, an attacker can read sensitive files on the server, potentially exposing confidential information or gaining unauthorized access.
How To Fix
Minimum fixed version
1.1-1
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
If upgrading python-django is not immediately feasible, a temporary workaround is to implement access controls and input validation to prevent directory traversal attacks. This can be done by validating user input and restricting access to sensitive files and directories. Here is an example of how to implement input validation in Python:
import os
def validate_path(path):
# Check if the path is within the allowed directory
allowed_directory = '/path/to/static/media'
full_path = os.path.join(allowed_directory, path)
if os.path.realpath(full_path).startswith(allowed_directory):
return True
else:
return False
This code snippet checks if the requested path is within the allowed directory and returns a boolean value indicating the validity of the path. It can be used to validate user input before serving static media files.
Conclusion
The directory traversal vulnerability in python-django allows remote attackers to read arbitrary files on the server. It is recommended to upgrade to version 1.1-1 or later to mitigate this vulnerability. If immediate upgrade is not possible, implementing access controls and input validation can provide temporary protection. For further assistance with vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for python-django →
FAQ
The vulnerability allows an attacker to read arbitrary files on the server, potentially exposing sensitive information or gaining unauthorized access.
Yes, there are known exploits for this vulnerability. Attackers can craft malicious URLs to traverse directories and access files outside the intended scope.
No, only versions 0.96 and 1.0 of python-django are affected. The vulnerability was fixed in version 1.1-1.
Yes, this vulnerability can be exploited remotely. Attackers can send crafted requests to the affected server to exploit the directory traversal flaw.
Yes, a patch is available for this vulnerability. Users should upgrade to version 1.1-1 or later of python-django to fix the issue.
Related vulnerabilities
Recent vulnerabilities recorded for python-django.