CVE-2012-4520: Django Arbitrary URL Generation Vulnerability
Summary
CVE-2012-4520: The django.http.HttpRequest.get_host function in Django 1.3.x before 1.3.4 and 1.4.x before 1.4.2 allows remote attackers to generate and display arbitrary URLs via crafted username and password Host header values. Affects django across 5 version ranges.
>= 1.3, < 1.3.4
>= 1.4, < 1.4.2
< 92d3430f12171f16f566c9050c40feefb830a4a3
< 9305c0e12d43c4df999c3301a1f0c742264a657e
< b45c377f8f488955e0c7069cad3f3dd21910b071
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 that simplify the development process. The vulnerability affects Django versions 1.3.x before 1.3.4 and 1.4.x before 1.4.2. The specific function impacted is django.http.HttpRequest.get_host. This function is responsible for determining the host name for the current request. However, due to a flaw, remote attackers can manipulate the username and password Host header values to generate and display arbitrary URLs.
Vulnerability Detail
The vulnerability allows attackers to craft malicious username and password Host header values, which can be used to generate and display arbitrary URLs. This can lead to various security issues, such as phishing attacks, unauthorized access to sensitive information, and potential remote code execution. The vulnerability arises from improper input validation and sanitization in the get_host function.
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 Django is not immediately feasible, a temporary workaround can be implemented by manually validating and sanitizing the username and password Host header values before using them to generate URLs. This can be done by implementing custom validation and sanitization logic in the application code that handles the request. Here's an example of how this can be done in Python:
import re
def sanitize_host_header(host_header):
# Remove any characters that are not allowed in a host header
sanitized_header = re.sub(r'[^a-zA-Z0-9.-]', '', host_header)
return sanitized_header
# Usage
host_header = request.META.get('HTTP_HOST')
sanitized_host = sanitize_host_header(host_header)
Conclusion
The Django Arbitrary URL Generation vulnerability (CVE-2012-4520) allows remote attackers to generate and display arbitrary URLs by manipulating the username and password Host header values. This can lead to various security risks, including phishing attacks and unauthorized access. It is crucial to upgrade Django to the patched versions (1.3.4 or 1.4.2) or implement the provided workaround to mitigate the vulnerability. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for django →
FAQ
The vulnerability allows attackers to generate and display arbitrary URLs, which can lead to various security issues, including phishing attacks, unauthorized access, and potential remote code execution.
The vulnerability affects Django versions 1.3.x before 1.3.4 and 1.4.x before 1.4.2.
To fix the vulnerability, it is recommended to upgrade Django to version 1.3.4 or 1.4.2, depending on the version being used.
If upgrading Django is not immediately feasible, a temporary workaround can be implemented by manually validating and sanitizing the username and password Host header values before using them to generate URLs.
You can find more information about this vulnerability in the official Django security advisory: [link to advisory]
Related vulnerabilities
Recent vulnerabilities recorded for django.