CVE-2023-51449
File traversal vulnerability in Gradio versions prior to 4.11.0 in the /file route
- CVSS 7.5
- CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- Input Validation and Sanitization
- Remote
Gradio is an open-source Python package that allows you to quickly build a demo or web application for your machine learning model, API, or any arbitary Python function. Versions of `gradio` prior to 4.11.0 contained a vulnerability in the `/file` route which made them susceptible to file traversal attacks in which an attacker could access arbitrary files on a machine running a Gradio app with a public URL (e.g. if the demo was created with `share=True`, or on Hugging Face Spaces) if they knew the path of files to look for. This issue has been patched in version 4.11.0.
- CVSS base score
- 7.5
- Published
- 2023-12-22
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Fixed by upgrading
- Yes
Solution
Upgrade to version 4.11.0 or newer of Gradio
Vulnerable code sample
import gradio as gr
def file_access(file_path):
with open(file_path, 'r') as file:
return file.read()
iface = gr.Interface(fn=file_access, inputs="text", outputs="text")
iface.launch(share=True)Patched code sample
import gradio as gr
import os
def file_access(file_path):
base_directory = "/directory"
path = os.path.join(base_directory, file_path)
if not path.startswith(base_directory):
raise ValueError("Invalid file path!")
if os.path.isfile(path):
with open(path, 'r') as file:
return file.read()
else:
return "File not found."
iface = gr.Interface(fn=file_access, inputs="text", outputs="text")
iface.launch(share=True)Cite this entry
@misc{vaitp:cve202351449,
title = {{File traversal vulnerability in Gradio versions prior to 4.11.0 in the /file route}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-51449},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-51449/}}
}
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 ::
