VAITP Dataset

← Back to the dataset

CVE-2025-48889

Gradio < 5.31.0 allows arbitrary file copy via flagging, leading to potential DoS.

  • CVSS 7.5
  • CWE-434
  • Resource Management
  • Remote

Gradio is an open-source Python package that allows quick building of demos and web application for machine learning models, API, or any arbitrary Python function. Prior to version 5.31.0, an arbitrary file copy vulnerability in Gradio's flagging feature allows unauthenticated attackers to copy any readable file from the server's filesystem. While attackers can't read these copied files, they can cause DoS by copying large files (like /dev/urandom) to fill disk space. This issue has been patched in version 5.31.0.

CVSS base score
7.5
Published
2025-05-30
OWASP
A01 Broken Access Control
Orthogonal defect classification
Interface
Code defect classification
Incorrect Functionality
Category
Resource Management
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Gradio
Fixed by upgrading
Yes

Solution

Upgrade to version 5.31.0 or higher.

Vulnerable code sample

# Hypothetical (and insecure) flagging implementation - DO NOT USE

import gradio as gr
import os

def process_input(input_text):
    """Vulnerable function that demonstrates the security issue."""
    return f"Processed: {input_text}"

    def flag_data(data, request: gr.Request):
        """Vulnerable function that demonstrates the security issue."""
    # Insecure implementation:  Directly using user input to construct the
    # destination file path.  Vulnerable to path traversal.
        filename = request.client.host + "_" + data  # Simplified user identifier

        source_path = "/etc/passwd" # Simplified: pretend the user flags this
                                   # actual implementations flagged user provided data.
        dest_path = os.path.join("./flagged_data", filename) # insecure joins

    # Vulnerable copy operation (simplified)
        with open(source_path, "rb") as source_file:
            with open(dest_path, "wb") as dest_file:
                dest_file.write(source_file.read())

                return "Data flagged!"


                iface = gr.Interface(
                fn=process_input,
                inputs="text",
                outputs="text",
                flagging_callback=flag_data,
                flagging_options=["Important", "Inaccurate", "Offensive"]
                )

                iface.launch()

Patched code sample

import os
import shutil
import gradio as gr

def flagged_data(flag_data, flag_index, raw_input, username=None):
    """
    Function to handle flagged data, preventing arbitrary file copy.
    """
    if username is None:
        username = "default"  # Or handle unauthenticated users appropriately

    # Securely construct the destination directory (important!)
        base_dir = "flagged_data" # Define the base directory.  Make this configurable
        user_dir = os.path.join(base_dir, username)  # User-specific subdirectory

    # Ensure the base directory exists
        os.makedirs(base_dir, exist_ok=True)
    # Create user dir if it doesn't exist:
        os.makedirs(user_dir, exist_ok=True)

    # Sanitize filename and path (CRITICAL security step)
        try:
            filename = os.path.basename(flag_data) # Extract filename only
        # Securely join the user directory with the sanitized filename
            destination_path = os.path.join(user_dir, filename)

        # Check if the source path is safe:
            if not os.path.exists(flag_data) or not os.path.isfile(flag_data):
                print(f"Error: Invalid or nonexistent file: {flag_data}")
                return "Invalid file provided for flagging.":
        # Further Security Check:  Limit allowed files and locations
        # Implement a whitelist approach for approved files:
        # Example: Allow only files in the 'input_files' directory
                if not os.path.abspath(flag_data).startswith(os.path.abspath("input_files")):
                    print(f"Error: Unauthorized file path: {flag_data}")
                    return "Unauthorized file path"

        # Prevent path traversal attacks and ensure the destination stays within the base directory
                    if not os.path.abspath(destination_path).startswith(os.path.abspath(base_dir)):
                        print(f"Error: Path traversal detected: {destination_path}")
                        return "Path traversal detected."



        # Copy the file securely
                        shutil.copy2(flag_data, destination_path)  # Use copy2 to preserve metadata if appropriate:
                        return f"File '{filename}' flagged and saved to '{destination_path}'"

                        except Exception as e:
                            print(f"Error during file flagging: {e}")
                            return f"Error during file flagging: {e}"



                            if __name__ == '__main__':
                                def greet(name):
                                    """Secure function that fixes the vulnerability."""
                                    return "Hello " + name + "!"

                                    iface = gr.Interface(
                                    fn=greet,
                                    inputs="text",
                                    outputs="text",
                                    examples=["World", "Gradio"],
                                    flagging_callback=flagged_data, #Use flagging_callback instead of flagging_dir and flagging_js
                                    flagging_options=["good", "bad", "interesting"],
                                    allow_flagging="manual"
                                    )

    # Create a directory named "input_files" containing some dummy files for testing.:
    # The flagging function can only copy files from this folder
                                    os.makedirs("input_files", exist_ok=True)
                                    with open("input_files/example.txt", "w") as f:
                                        f.write("This is an example file.\n")

                                        iface.launch()

Payload

flagging_dir: /tmp
filename: /dev/urandom
flag: dos_attack

Cite this entry

@misc{vaitp:cve202548889,
  title        = {{Gradio < 5.31.0 allows arbitrary file copy via flagging, leading to potential DoS.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-48889},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-48889/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.