CVE-2021-43831
File access vulnerability in Gradio < 2.5.0 via shared links
- CVSS 7.7
- CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- Input Validation and Sanitization
- Remote
Gradio is an open source framework for building interactive machine learning models and demos. In versions prior to 2.5.0 there is a vulnerability that affects anyone who creates and publicly shares Gradio interfaces. File paths are not restricted and users who receive a Gradio link can access any files on the host computer if they know the file names or file paths. This is limited only by the host operating system. Paths are opened in read only mode. The problem has been patched in gradio 2.5.0.
- CVSS base score
- 7.7
- Published
- 2021-12-15
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Direct Object References (IDOR)
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- Gradio
- Fixed by upgrading
- Yes
Solution
Update Gradio to version 2.5.0 or higher.
Vulnerable code sample
import gradio as gr
def vulnerable_file_access(file_path):
# No restrictions on file paths
with open(file_path, 'r') as file:
return file.read()
iface = gr.Interface(fn=vulnerable_file_access, inputs="text", outputs="text")
iface.launch()Patched code sample
import gradio as gr
import os
def safe_file_access(file_path):
# Restrict access to a specific directory
base_directory = "/safe/directory/"
full_path = os.path.join(base_directory, file_path)
# Ensure the path is within the allowed directory
if not full_path.startswith(base_directory):
raise ValueError("Access to this file path is not allowed.")
with open(full_path, 'r') as file:
return file.read()
iface = gr.Interface(fn=safe_file_access, inputs="text", outputs="text")
iface.launch()Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- secure path hotfix (gradio-app/gradio)
gradio/networking.py · file
Cite this entry
@misc{vaitp:cve202143831,
title = {{File access vulnerability in Gradio < 2.5.0 via shared links}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-43831},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-43831/}}
}
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 ::
