{"id":1051,"cve":"CVE-2024-47167","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2024-47167\/","cwe":"CWE-918","cwe_number":918,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/918","cvss_score":6.9,"published":"2024-10-10","owasp":"A04 Insecure Design","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"Server-Side Request Forgery (SSRF)","scope":"Remote","impact":"Data Theft","summary":"SSRF vulnerability in Gradio allows attacks via user-controlled URLs.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2024-47167\/","description":"Gradio is an open-source Python package designed for quick prototyping. This vulnerability relates to **Server-Side Request Forgery (SSRF)** in the `\/queue\/join` endpoint. Gradio\u2019s `async_save_url_to_cache` function allows attackers to force the Gradio server to send HTTP requests to user-controlled URLs. This could enable attackers to target internal servers or services within a local network and possibly exfiltrate data or cause unwanted internal requests. Additionally, the content from these URLs is stored locally, making it easier for attackers to upload potentially malicious files to the server. This impacts users deploying Gradio servers that use components like the Video component which involve URL fetching. Users are advised to upgrade to `gradio>=5` to address this issue.  As a workaround, users can disable or heavily restrict URL-based inputs in their Gradio applications to trusted domains only. Additionally, implementing stricter URL validation (such as allowinglist-based validation) and ensuring that local or internal network addresses cannot be requested via the `\/queue\/join` endpoint can help mitigate the risk of SSRF attacks.","solution":"Upgrade to `gradio>=5` and implement allowlist-based URL validation.","affected_component":"Gradio","fixed_by_upgrading":true,"vulnerable_code":"import gradio as gr\nimport requests\n\ndef fetch_url(url):\n    response = requests.get(url)\n    return response.text\n\niface = gr.Interface(fn=fetch_url, inputs=\"text\", outputs=\"text\")\niface.launch()","patched_code":"import gradio as gr\nimport requests\nfrom urllib.parse import urlparse\n\ndef is_valid_url(url):\n    try:\n        parsed_url = urlparse(url)\n        if parsed_url.scheme not in [\"http\", \"https\"]:\n            return False\n        if parsed_url.hostname in ['localhost', '127.0.0.1', '0.0.0.0']:\n            return False\n        return True\n    except ValueError:\n        return False\n\ndef fetch_url(url):\n    if not is_valid_url(url):\n        return \"Invalid URL. Please provide a valid HTTP(S) URL.\"\n\n    try:\n        response = requests.get(url, timeout=5)\n        response.raise_for_status()\n        return response.text\n    except requests.exceptions.RequestException as e:\n        return f\"Error fetching URL: {str(e)}\"\n\niface = gr.Interface(fn=fetch_url, inputs=\"text\", outputs=\"text\")\niface.launch()\n","payload_needed":true,"payload":"```plaintext\nhttp:\/\/localhost:8080\/admin\n```","payload_status":"available","published_fix":[],"references":null}