VAITP Dataset

← Back to the dataset

CVE-2024-8021

Open redirect in gradio-app/gradio allows redirection to malicious sites via URL encoding.

  • CVSS 6.1
  • CWE-601
  • Input Validation and Sanitization
  • Remote

An open redirect vulnerability exists in the latest version of gradio-app/gradio. The vulnerability allows an attacker to redirect users to a malicious website by URL encoding. This can be exploited by sending a crafted request to the application, which results in a 302 redirect to an attacker-controlled site.

CVSS base score
6.1
Published
2025-03-20
OWASP
A03 Injection
Orthogonal defect classification
Interface
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Open Redirects
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
gradio-app/g
Fixed by upgrading
Yes

Solution

Upgrade to gradio>=4.16.0

Vulnerable code sample

from flask import Flask, request, redirect, url_for

app = Flask(__name__)

@app.route('/redirect')
def redirect_url():
    target = request.args.get('url')
    # Vulnerable code:  No validation or sanitization of the URL
    return redirect(target, code=302)

if __name__ == '__main__':
    app.run(debug=True)

Patched code sample

from urllib.parse import urlparse, urlunparse

def is_safe_url(url, allowed_schemes=('http', 'https')):
    """
    Checks if a URL is safe to redirect to.

    Args:
        url (str): The URL to check.
        allowed_schemes (tuple): A tuple of allowed schemes (e.g., ('http', 'https')).

    Returns:
        bool: True if the URL is safe, False otherwise.
    """
    try:
        result = urlparse(url)
        return result.scheme in allowed_schemes
    except:
        return False  # Handle parsing errors as unsafe


def safe_redirect(url):
    """
    Safely redirects to the given URL if it is safe.

    Args:
        url (str): The URL to redirect to.

    Returns:
        str: The safe URL or a default URL if the provided URL is unsafe.
    """
    if is_safe_url(url):
        return url
    else:
        return "/default_safe_page"  # Redirect to a safe default page


# Example usage (simulating the fix):
def process_redirect_url(redirect_url):
    return safe_redirect(redirect_url)


if __name__ == '__main__':
    # Vulnerable Example
    # redirect_url = "https://www.example.com" # No URL encoding. This is a safe URL so the below would work if no check.
    # redirect_url = "%68%74%74%70%73%3a%2f%2f%77%77%77%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d"  # URL encoded safe url (example.com)
    # redirect_url = "%68%74%74%70%3a%2f%2f%61%74%74%61%63%6b%2e%63%6f%6d" # URL encoded to attack.com
    # redirect_url = "javascript:alert('XSS')" # javascript payload.

    # Fixed Example using safe_redirect and is_safe_url
    redirect_url = input("Enter the redirect URL: ")
    safe_url = process_redirect_url(redirect_url)

    print(f"Redirecting to: {safe_url}") # print not actually redirecting to avoid automatic redirects to attacker site during testing

Payload

%2F%2Fevil.com

Cite this entry

@misc{vaitp:cve20248021,
  title        = {{Open redirect in gradio-app/gradio allows redirection to malicious sites via URL encoding.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-8021},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-8021/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::