Overview
An Open Redirect vulnerability occurs when an application uses user-supplied input to redirect the user to a URL, but fails to validate that URL. An attacker can craft a link to your trusted website that, when clicked, redirects the user to a malicious site. This is often used in phishing attacks, as the user only sees your legitimate domain in the link.Business Impact
This vulnerability is a powerful tool for phishing. Attackers can steal user credentials by redirecting them to a clone of your login page. It abuses the trust users have in your domain, leading to account compromise and reputational damage.Reference Details
CWE ID: CWE-601
OWASP Top 10 (2021): A01:2021 - Broken Access Control
Severity: Medium
Framework-Specific Analysis and Remediation
This vulnerability is common in login pages, logout endpoints, and any “interstitial” page that uses a query parameter (e.g.,?next=, ?returnTo=) to control navigation. The key to mitigation is to never trust this user-supplied URL. It must be validated against an allow-list or checked to ensure it’s a local path.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
A login view that takes a?next parameter and uses redirect(request.GET.get('next')).Vulnerable Scenario 1: A Login Redirect
Vulnerable Scenario 2: A “Change Language” Endpoint
A view that sets a language cookie and redirects the user back to where they came from.Mitigation and Best Practices
Usedjango.utils.http.url_has_allowed_host_and_scheme to validate the next_url. You must pass it the allowed hosts (from settings.ALLOWED_HOSTS). For relative paths, you can also check next_url.startswith('/').Secure Code Example
Testing Strategy
Write an integration test that logs in and passes a maliciousnext parameter. Assert that the response redirects to the default page (/), not the malicious URL.
