{"id":1040,"cve":"CVE-2024-47166","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2024-47166\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":2.3,"published":"2024-10-10","owasp":"A05 Security Misconfiguration","odc":"Checking","cdc":"Incorrect Check","category":"Information Leakage","subcategory":"Path Traversal","scope":"Remote","impact":"Information Disclosure","summary":"One-level path traversal in Gradio exposes sensitive custom component code.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2024-47166\/","description":"Gradio is an open-source Python package designed for quick prototyping. This vulnerability involves a **one-level read path traversal** in the `\/custom_component` endpoint. Attackers can exploit this flaw to access and leak source code from custom Gradio components by manipulating the file path in the request. Although the traversal is limited to a single directory level, it could expose proprietary or sensitive code that developers intended to keep private. This impacts users who have developed custom Gradio components and are hosting them on publicly accessible servers. Users are advised to upgrade to `gradio>=4.44` to address this issue. As a workaround, developers can sanitize the file paths and ensure that components are not stored in publicly accessible directories.","solution":"Upgrade to `gradio>=4.44` and sanitize file paths.","affected_component":"Gradio","fixed_by_upgrading":true,"vulnerable_code":"import gradio as gr\n\ndef load_custom_component(file_path):\n    with open(file_path, 'r') as f:\n        return f.read()\n\niface = gr.Interface(fn=load_custom_component, inputs=\"text\", outputs=\"text\")\niface.launch()","patched_code":"import gradio as gr\nimport os\n\ndef load_custom_component(file_path):\n    if '..' in file_path or file_path.startswith('\/'):\n        raise ValueError(\"Invalid file path.\")\n    \n    base_directory = \"components\/\"\n    full_path = os.path.join(base_directory, file_path)\n\n    if not os.path.isfile(full_path):\n        raise FileNotFoundError(\"Component not found.\")\n\n    with open(full_path, 'r') as f:\n        return f.read()\n\niface = gr.Interface(fn=load_custom_component, inputs=\"text\", outputs=\"text\")\niface.launch()","payload_needed":true,"payload":"```\n..\/..\/sensitive_file.py\n```","payload_status":"available","published_fix":[],"references":null}