CVE-2024-47167
SSRF vulnerability in Gradio allows attacks via user-controlled URLs.
- CVSS 6.9
- CWE-918
- Input Validation and Sanitization
- Remote
Gradio is an open-source Python package designed for quick prototyping. This vulnerability relates to **Server-Side Request Forgery (SSRF)** in the `/queue/join` endpoint. Gradio’s `async_save_url_to_cache` function allows attackers to force the Gradio server to send HTTP requests to user-controlled URLs. This could enable attackers to target internal servers or services within a local network and possibly exfiltrate data or cause unwanted internal requests. Additionally, the content from these URLs is stored locally, making it easier for attackers to upload potentially malicious files to the server. This impacts users deploying Gradio servers that use components like the Video component which involve URL fetching. Users are advised to upgrade to `gradio>=5` to address this issue. As a workaround, users can disable or heavily restrict URL-based inputs in their Gradio applications to trusted domains only. Additionally, implementing stricter URL validation (such as allowinglist-based validation) and ensuring that local or internal network addresses cannot be requested via the `/queue/join` endpoint can help mitigate the risk of SSRF attacks.
- CWE
- CWE-918
- CVSS base score
- 6.9
- Published
- 2024-10-10
- OWASP
- A10 Insufficient Logging & Monitoring
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Server-Side Request Forgery (SSRF)
- Accessibility scope
- Remote
- Impact
- Data Theft
- Affected component
- Gradio
- Fixed by upgrading
- Yes
Solution
Upgrade to `gradio>=5` and implement allowlist-based URL validation.
Vulnerable code sample
import gradio as gr
import requests
def fetch_url(url):
response = requests.get(url)
return response.text
iface = gr.Interface(fn=fetch_url, inputs="text", outputs="text")
iface.launch()Patched code sample
import gradio as gr
import requests
from urllib.parse import urlparse
def is_valid_url(url):
try:
parsed_url = urlparse(url)
if parsed_url.scheme not in ["http", "https"]:
return False
if parsed_url.hostname in ['localhost', '127.0.0.1', '0.0.0.0']:
return False
return True
except ValueError:
return False
def fetch_url(url):
if not is_valid_url(url):
return "Invalid URL. Please provide a valid HTTP(S) URL."
try:
response = requests.get(url, timeout=5)
response.raise_for_status()
return response.text
except requests.exceptions.RequestException as e:
return f"Error fetching URL: {str(e)}"
iface = gr.Interface(fn=fetch_url, inputs="text", outputs="text")
iface.launch()Payload
http://localhost:8080/admin
Cite this entry
@misc{vaitp:cve202447167,
title = {{SSRF vulnerability in Gradio allows attacks via user-controlled URLs.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-47167},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-47167/}}
}
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 ::
