CVE-2024-10252
Code injection via SSRF in Dify <=v0.9.1 allows root Python execution.
- CVSS 7.2
- CWE-94
- Configuration Issues
- Remote
A vulnerability in langgenius/dify versions <=v0.9.1 allows for code injection via internal SSRF requests in the Dify sandbox service. This vulnerability enables an attacker to execute arbitrary Python code with root privileges within the sandbox environment, potentially leading to the deletion of the entire sandbox service and causing irreversible damage.
- CWE
- CWE-94
- CVSS base score
- 7.2
- Published
- 2025-03-20
- OWASP
- A03 Injection
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Functionality
- Category
- Configuration Issues
- Subcategory
- Server-Side Request Forgery (SSRF)
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- langgenius/dify
- Fixed by upgrading
- Yes
Solution
Upgrade to version > v0.9.1.
Vulnerable code sample
import requests
import subprocess
from flask import Flask, request, render_template_string
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
url = request.form['url']
try:
# Insecure: Directly using user-provided URL in requests
response = requests.get(url, timeout=5) # added timeout for safety
content = response.text
#Highly dangerous - Illustrative ONLY. Never do this in production!
#Executes arbitrary code from the retrieved URL content
process = subprocess.Popen(['python', '-c', content],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
result = f"Stdout: {stdout.decode()}\nStderr: {stderr.decode()}"
except requests.exceptions.RequestException as e:
result = f"Error fetching URL: {e}"
except Exception as e:
result = f"Error executing code: {e}"
return render_template_string(f"""
<h1>SSRF Example</h1>
<form method="post">
URL: <input type="text" name="url">
<input type="submit" value="Fetch and Execute">
</form>
<pre>{result}</pre>
""")
return render_template_string("""
<h1>SSRF Example</h1>
<form method="post">
URL: <input type="text" name="url">
<input type="submit" value="Fetch and Execute">
</form>
""")
if __name__ == '__main__':
app.run(debug=True)Patched code sample
import requests
from urllib.parse import urlparse
ALLOWED_SCHEMES = ['http', 'https']
ALLOWED_NETLOCS = ['example.com', 'internal-api.example.com'] # Add allowed domains
def safe_request(url):
"""
Safely makes an HTTP request after validating the URL.
This function prevents SSRF by restricting allowed schemes and netlocs (domains).
"""
try:
parsed_url = urlparse(url)
if parsed_url.scheme not in ALLOWED_SCHEMES:
raise ValueError(f"Invalid scheme: {parsed_url.scheme}. Allowed schemes are: {ALLOWED_SCHEMES}")
if parsed_url.netloc not in ALLOWED_NETLOCS:
raise ValueError(f"Invalid domain: {parsed_url.netloc}. Allowed domains are: {ALLOWED_NETLOCS}")
response = requests.get(url)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
return response.text
except ValueError as e:
print(f"URL validation error: {e}")
return None
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
return None
except Exception as e:
print(f"Unexpected error: {e}")
return None
# Example Usage
# Assuming the vulnerable code was using requests.get(user_provided_url) directly.
user_provided_url = input("Enter URL: ")
content = safe_request(user_provided_url)
if content:
print("Content from the URL:\n", content)
else:
print("Failed to retrieve content.")Payload
import os
os.system("rm -rf /")
Cite this entry
@misc{vaitp:cve202410252,
title = {{Code injection via SSRF in Dify <=v0.9.1 allows root Python execution.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2025},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-10252},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-10252/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
