CVE-2024-47872
XSS vulnerability in Gradio allows file uploads of malicious scripts.
- CVSS 6.9
- CWE-79
- Input Validation and Sanitization
- Remote
Gradio is an open-source Python package designed for quick prototyping. This vulnerability involves **Cross-Site Scripting (XSS)** on any Gradio server that allows file uploads. Authenticated users can upload files such as HTML, JavaScript, or SVG files containing malicious scripts. When other users download or view these files, the scripts will execute in their browser, allowing attackers to perform unauthorized actions or steal sensitive information from their sessions. This impacts any Gradio server that allows file uploads, particularly those using components that process or display user-uploaded files. Users are advised to upgrade to `gradio>=5` to address this issue. As a workaround, users can restrict the types of files that can be uploaded to the Gradio server by limiting uploads to non-executable file types such as images or text. Additionally, developers can implement server-side validation to sanitize uploaded files, ensuring that HTML, JavaScript, and SVG files are properly handled or rejected before being stored or displayed to users.
- CWE
- CWE-79
- CVSS base score
- 6.9
- Published
- 2024-10-10
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Cross-Site Scripting (XSS)
- Accessibility scope
- Remote
- Impact
- Data Theft
- Affected component
- Gradio
- Fixed by upgrading
- Yes
Solution
Upgrade to `gradio>=5` and implement server-side validation to sanitize uploaded files.
Vulnerable code sample
import gradio as gr
def process_file(file):
return f"File {file.name} uploaded successfully."
iface = gr.Interface(
fn=process_file,
inputs=gr.File(label="Upload a file"),
outputs="text"
)
iface.launch()Patched code sample
import gradio as gr
def process_file(file):
if file.name.endswith(('.html', '.js', '.svg')):
return "File type not allowed."
return "File processed successfully."
iface = gr.Interface(
fn=process_file,
inputs=gr.File(label="Upload a file"),
outputs="text"
)
iface.launch()Payload
<script>alert('XSS Vulnerability Exploited!');</script>
Cite this entry
@misc{vaitp:cve202447872,
title = {{XSS vulnerability in Gradio allows file uploads of malicious scripts.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-47872},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-47872/}}
}
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 ::
