CVE-2012-4520: Django Arbitrary URL Generation
Summary
CVE-2012-4520: Django Allows Arbitrary URL Generation. Affects django across 2 version ranges.
>= 1.3, < 1.3.4
>= 1.4, < 1.4.2
Fixed in 1.3.4 or 1.4.2, depending on the release line you run. How to fix ↓
Also tracked for
- python-django · Debian:11
The same CVE-2012-4520 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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
Django is a popular Python web framework used for building web applications. It provides a set of tools and libraries for handling various web development tasks, including URL routing, database management, and user authentication. The vulnerability described in this report affects Django versions 1.3.x before 1.3.4 and 1.4.x before 1.4.2. Django's HttpRequest.get_host function is susceptible to a security flaw that allows remote attackers to generate and display arbitrary URLs by manipulating the username and password Host header values.
Vulnerability Detail
The vulnerability arises from a lack of proper input validation in the get_host function of Django's HttpRequest class. By crafting malicious username and password values in the Host header, an attacker can manipulate the URL generation process and potentially trick users into visiting arbitrary URLs. This could lead to various security risks, such as phishing attacks, cross-site scripting (XSS), or unauthorized access to sensitive information.
How To Fix
Latest published version: 6.1.2 as of 22 Oct 2026
pip install --upgrade "django==6.1.2"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
>= 1.3, < 1.3.41.3.4pip install --upgrade "django==1.3.4" -
>= 1.4, < 1.4.21.4.2pip install --upgrade "django==1.4.2"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading to a patched version of Django is not immediately feasible, a temporary workaround can be implemented by manually validating and sanitizing the Host header values before using them in URL generation. This can be done by implementing custom request processing middleware that checks and filters the username and password values in the Host header. Here is an example of how this can be achieved in Django:
from django.http import HttpRequest
class CustomHostValidationMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Validate and sanitize the Host header values
request.META['HTTP_HOST'] = sanitize_host(request.META.get('HTTP_HOST'))
return self.get_response(request)
def sanitize_host(host):
# Implement custom validation and sanitization logic
# Return the sanitized host value
pass
By implementing this middleware, the Host header values can be validated and sanitized before being used in URL generation, mitigating the vulnerability.
Conclusion
The vulnerability in Django's HttpRequest.get_host function allows remote attackers to generate and display arbitrary URLs by manipulating the username and password Host header values. To mitigate this vulnerability, it is crucial to upgrade to a patched version of Django (1.3.4 or later for Django 1.3.x, and 1.4.2 or later for Django 1.4.x). If immediate upgrading is not possible, implementing custom request processing middleware to validate and sanitize the Host header values can serve as a temporary workaround. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for django →
FAQ
This vulnerability allows remote attackers to manipulate URL generation in Django, potentially leading to security risks such as phishing attacks, cross-site scripting (XSS), or unauthorized access to sensitive information.
Django versions 1.3.x before 1.3.4 and 1.4.x before 1.4.2 are affected by this vulnerability.
You can use the Vulert Playground (https://vulert.com/scanner) to check if your application is affected by this vulnerability. Simply provide your Pipfile.lock file, and Vulert will analyze it for any open-source vulnerabilities, including this one.
Yes, a temporary workaround is available by implementing custom request processing middleware that validates and sanitizes the Host header values before URL generation. Please refer to the 'workaround' section of this report for more details.
You can find more information about this vulnerability, including the technical details and the fixed versions of Django, in the official advisory provided by the Django project. The advisory can be accessed at: https://github.com/pypa/advisory-database/blob/main/vulns/django/PYSEC-2012-7.yaml
References
Related vulnerabilities
Recent vulnerabilities recorded for django.