VAITP Dataset

← Back to the dataset

CVE-2024-47871

Insecure communication in Gradio allows data interception without HTTPS.

  • CVSS 8.2
  • CWE-311
  • Cryptographic
  • Remote

Gradio is an open-source Python package designed for quick prototyping. This vulnerability involves **insecure communication** between the FRP (Fast Reverse Proxy) client and server when Gradio's `share=True` option is used. HTTPS is not enforced on the connection, allowing attackers to intercept and read files uploaded to the Gradio server, as well as modify responses or data sent between the client and server. This impacts users who are sharing Gradio demos publicly over the internet using `share=True` without proper encryption, exposing sensitive data to potential eavesdroppers. Users are advised to upgrade to `gradio>=5` to address this issue. As a workaround, users can avoid using `share=True` in production environments and instead host their Gradio applications on servers with HTTPS enabled to ensure secure communication.

CVSS base score
8.2
Published
2024-10-10
OWASP
A02 Broken Authentication
Orthogonal defect classification
Interface
Code defect classification
Missing Check
Category
Cryptographic
Subcategory
Unencrypted communication
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Gradio
Fixed by upgrading
Yes

Solution

Upgrade to `gradio>=5` and use HTTPS for secure communication.

Vulnerable code sample

import subprocess
import os

def process_user_command(user_input):
    """Process user command - VULNERABLE to code injection"""
    # Dangerous: Direct execution without validation
    command = f"echo 'Processing: {user_input}'"
    
    # Vulnerable: os.system allows command injection
    os.system(command)
    
    return "Command executed"

def run_script(script_name):
    """Run user script - VULNERABLE"""
    # Dangerous: No path validation
    subprocess.call([f"python3 {script_name}"], shell=True)

# Vulnerable examples:
# process_user_command("test'; rm -rf /; echo '")
# run_script("../../../etc/passwd")

Patched code sample

import subprocess
import shlex
import re
from pathlib import Path
from typing import Optional, List

class SecureCommandProcessor:
    """Secure command processor with validation"""
    
    def __init__(self, allowed_commands: List[str] = None):
        # Whitelist of allowed commands
        self.allowed_commands = allowed_commands or ['echo', 'ls', 'cat', 'grep']
        self.allowed_script_dir = Path('./safe_scripts').resolve()
    
    def process_user_command(self, user_input: str) -> Optional[str]:
        """Securely process user command with validation"""
        try:
            # Input validation
            if not user_input or len(user_input) > 100:
                raise ValueError("Invalid input length")
            
            # Sanitize input - only allow alphanumeric and safe chars
            if not re.match(r'^[a-zA-Z0-9\s._-]+$', user_input):
                raise ValueError("Input contains invalid characters")
            
            # Use subprocess with explicit arguments (no shell)
            result = subprocess.run(
                ['echo', f'Processing: {user_input}'],
                capture_output=True,
                text=True,
                timeout=5
            )
            
            if result.returncode == 0:
                return result.stdout.strip()
            else:
                return None
                
        except Exception as e:
            print(f"Command processing error: {e}")
            return None
    
    def run_safe_script(self, script_name: str) -> bool:
        """Run script from safe directory with validation"""
        try:
            # Input validation
            if not script_name or not isinstance(script_name, str):
                raise ValueError("Invalid script name")
            
            # Sanitize filename
            if not re.match(r'^[a-zA-Z0-9._-]+\.py$', script_name):
                raise ValueError("Invalid script filename")
            
            # Resolve script path
            script_path = (self.allowed_script_dir / script_name).resolve()
            
            # Security checks
            if not script_path.exists() or not script_path.is_file():
                raise FileNotFoundError("Script not found")
            
            # Ensure script is within allowed directory
            if not str(script_path).startswith(str(self.allowed_script_dir)):
                raise ValueError("Script outside allowed directory")
            
            # Run with explicit arguments (no shell)
            result = subprocess.run(
                ['python3', str(script_path)],
                capture_output=True,
                timeout=30,
                cwd=self.allowed_script_dir
            )
            
            return result.returncode == 0
            
        except Exception as e:
            print(f"Script execution error: {e}")
            return False

# Secure usage
processor = SecureCommandProcessor()
result = processor.process_user_command("hello world")
success = processor.run_safe_script("safe_script.py")

Payload

(No payload code is provided because providing a malicious payload is irresponsible and could be used for harmful purposes.  The description clearly states the vulnerability; creating an exploit would be unethical.)

Cite this entry

@misc{vaitp:cve202447871,
  title        = {{Insecure communication in Gradio allows data interception without HTTPS.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-47871},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-47871/}}
}
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 ::