CVE-2015-0220: Cross-Site Scripting (XSS) in Django
Summary
CVE-2015-0220: The django.util.http.is_safe_url function in Django before 1.4.18, 1.6.x before 1.6.10, and 1.7.x before 1.7.3 does not properly handle leading whitespaces, which allows remote attackers to conduct cross-site scripting (... Affects django across 3 version ranges.
< 1.4.18
>= 1.5, < 1.6.10
>= 1.7, < 1.7.3
Fixed in 1.4.18, 1.6.10 or 1.7.3, depending on the release line you run. How to fix ↓
Also tracked for
- python-django · Debian:11
The same CVE-2015-0220 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 that provides a set of tools and libraries for building web applications. It offers features such as URL routing, template rendering, and database management. The vulnerability identified as CVE-2015-0220 affects versions of Django prior to 1.4.18, 1.6.x prior to 1.6.10, and 1.7.x prior to 1.7.3. This vulnerability specifically targets the django.util.http.is_safe_url function, which is responsible for handling redirect URLs. The function fails to properly handle leading whitespaces, allowing remote attackers to exploit this flaw and conduct cross-site scripting (XSS) attacks by crafting malicious URLs.
Vulnerability Detail
The vulnerability arises from the inadequate handling of leading whitespaces in the django.util.http.is_safe_url function. By injecting a crafted URL with a "\njavascript:" prefix, an attacker can execute arbitrary JavaScript code in the context of a victim's browser. This can lead to various security risks, including session hijacking, data theft, and unauthorized actions on behalf of the victim. It is important to note that this vulnerability is specific to redirect URLs and can be exploited by tricking users into clicking on malicious links.
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.4.181.4.18pip install --upgrade "django==1.4.18" -
>= 1.5, < 1.6.101.6.10pip install --upgrade "django==1.6.10" -
>= 1.7, < 1.7.31.7.3pip install --upgrade "django==1.7.3"
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 redirect URLs. Developers can use functions like Django's url_has_allowed_host_and_scheme to ensure that the URL is safe before performing the redirect. Here is an example of how to use this function:
from django.utils.http import url_has_allowed_host_and_scheme
url = request.GET.get('next', '')
if url_has_allowed_host_and_scheme(url, allowed_hosts=None):
# Perform the redirect
else:
# Handle the invalid URL
By explicitly checking the URL's host and scheme, developers can mitigate the risk of XSS attacks.
Conclusion
The vulnerability identified as CVE-2015-0220 in Django versions prior to 1.4.18, 1.6.x prior to 1.6.10, and 1.7.x prior to 1.7.3 allows remote attackers to conduct cross-site scripting (XSS) attacks by exploiting the inadequate handling of leading whitespaces in the django.util.http.is_safe_url function. To mitigate this vulnerability, it is crucial to upgrade Django to the patched versions or implement the provided workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for django →
FAQ
The vulnerability allows remote attackers to execute arbitrary JavaScript code in the context of a victim's browser, potentially leading to session hijacking, data theft, and unauthorized actions.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. Simply provide your Pipfile.lock and the playground will analyze it for any open-source vulnerabilities, including CVE-2015-0220.
There have been reported cases of this vulnerability being exploited in the wild. It is crucial to promptly address this issue to prevent potential attacks on your web application.
Yes, Django has released patches for versions 1.4.18, 1.6.10, and 1.7.3, which address this vulnerability. It is recommended to upgrade to the latest patched version of Django.
While upgrading Django is the recommended solution, developers can implement a temporary workaround by manually validating and sanitizing redirect URLs. By checking the URL's host and scheme, the risk of XSS attacks can be reduced.
Related vulnerabilities
Recent vulnerabilities recorded for django.