VAITP Dataset

← Back to the dataset

CVE-2024-47166

One-level path traversal in Gradio exposes sensitive custom component code.

  • CVSS 2.3
  • CWE-22
  • Information Leakage
  • Remote

Gradio is an open-source Python package designed for quick prototyping. This vulnerability involves a **one-level read path traversal** in the `/custom_component` endpoint. Attackers can exploit this flaw to access and leak source code from custom Gradio components by manipulating the file path in the request. Although the traversal is limited to a single directory level, it could expose proprietary or sensitive code that developers intended to keep private. This impacts users who have developed custom Gradio components and are hosting them on publicly accessible servers. Users are advised to upgrade to `gradio>=4.44` to address this issue. As a workaround, developers can sanitize the file paths and ensure that components are not stored in publicly accessible directories.

CVSS base score
2.3
Published
2024-10-10
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Information Leakage
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Gradio
Fixed by upgrading
Yes

Solution

Upgrade to `gradio>=4.44` and sanitize file paths.

Vulnerable code sample

import gradio as gr

def load_custom_component(file_path):
    with open(file_path, 'r') as f:
        return f.read()

iface = gr.Interface(fn=load_custom_component, inputs="text", outputs="text")
iface.launch()

Patched code sample

import gradio as gr
import os

def load_custom_component(file_path):
    if '..' in file_path or file_path.startswith('/'):
        raise ValueError("Invalid file path.")
    
    base_directory = "components/"
    full_path = os.path.join(base_directory, file_path)

    if not os.path.isfile(full_path):
        raise FileNotFoundError("Component not found.")

    with open(full_path, 'r') as f:
        return f.read()

iface = gr.Interface(fn=load_custom_component, inputs="text", outputs="text")
iface.launch()

Payload

../../sensitive_file.py

Cite this entry

@misc{vaitp:cve202447166,
  title        = {{One-level path traversal in Gradio exposes sensitive custom component code.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-47166},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-47166/}}
}
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 ::