Summary
Gradio before 6.20.0 exposes an open redirect and server-side request forgery risk via the /gradio_api/file= endpoint's file_fetch() handling of unvalidated URLs.
By supplying crafted HTTP/HTTPS URLs, an attacker can redirect users to arbitrary sites or coerce the server into making requests to internal services, potentially leaking sensitive cloud credentials.
Affected context
This vulnerability appears in Gradio deployments that expose the /gradio_api/file= endpoint and rely on file_fetch() to retrieve remote resources over HTTP or HTTPS.
The risk is higher when the Gradio server has network access to internal resources such as cloud metadata endpoints, private APIs, or management interfaces.
Environments that treat URLs from user input as trusted without additional validation or isolation are more likely to be affected.
Exploit preconditions
- Attack surface: Publicly accessible Gradio instances exposing /gradio_api/file=.
- Required access: Ability to supply or influence the URL parameter passed to file_fetch(), typically via UI controls, API calls, or embedded links.
- Trigger point: The server processes the provided HTTP/HTTPS URL and fetches the remote content without adequate validation or restriction.
- Why exploitation is possible: URL inputs are treated as trusted, allowing requests to arbitrary domains and internal network addresses, and enabling redirection logic that forwards users to attacker-controlled destinations.
Why this happens
The underlying issue stems from insufficient validation and restriction of user-supplied URLs in the file_fetch() function.
For SSRF (CWE-918), the server accepts arbitrary HTTP/HTTPS URLs and initiates outbound requests on behalf of the user, without enforcing allowlists, blocking internal address ranges, or restricting access to sensitive metadata services.
For open redirect (CWE-601), user-controlled URLs are used in redirect flows without checking whether the destination is safe or belongs to a trusted origin.
Together, these insecure patterns allow attackers to leverage Gradio as a proxy into internal networks and to misdirect users to malicious sites.
Potential impact
- Attackers may retrieve cloud instance metadata, including IAM role or access credentials.
- Attackers could access internal HTTP-based services not directly exposed to the internet.
- Users can be redirected to phishing pages, malware-hosting sites, or credential-harvesting domains.
- Session tokens, API keys, or other sensitive configuration data available via internal endpoints may be exposed.
- The Gradio server can be abused as a pivot point for further internal reconnaissance.
General mitigation guidance
Mitigation typically involves reducing trust in user-supplied URLs and enforcing strict network access controls from server-side components.
Common defensive patterns include:
- Applying robust URL validation, including scheme checks and domain allowlists for remote resource fetching.
- Blocking requests to link-local, loopback, private IP ranges, and well-known cloud metadata endpoints from application-level HTTP clients.
- Decoupling user input from redirect targets, using fixed or mapped internal URLs instead of directly redirecting to arbitrary user-provided destinations.
- Running application services with least-privilege network permissions and avoiding unnecessary access to internal management interfaces or metadata services.
- Introducing proxy or gateway layers with outbound request policies to constrain what the application can reach.
How teams detect issues like this
Detection can focus on both code-level patterns and runtime behavior:
- Static analysis and code review to flag functions that perform outbound HTTP requests using user-controlled URL parameters without validation or filtering.
- Identification of redirect logic where user input directly populates Location headers or redirect targets.
- Logging and monitoring of outbound HTTP traffic from the application, especially calls to metadata endpoints, internal IP ranges, or unusual domains.
- Enforcing security policies in CI/CD that require validation of external URLs and restrict SSRF-prone patterns, potentially supported by automated scanning tools.

