CVE-2025-6166
Agent-Zero <= 0.8.4 path traversal in image_get.py via path argument.
- CVSS 5.1
- CWE-22
- Input Validation and Sanitization
- Remote
A vulnerability was found in frdel Agent-Zero up to 0.8.4. It has been rated as problematic. This issue affects the function image_get of the file /python/api/image_get.py. The manipulation of the argument path leads to path traversal. Upgrading to version 0.8.4.1 is able to address this issue. The identifier of the patch is 5db74202d632306a883ccce7339c5bdba0d16c5a. It is recommended to upgrade the affected component.
- CWE
- CWE-22
- CVSS base score
- 5.1
- Published
- 2025-06-17
- OWASP
- A01 Broken Access Control
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- Agent-Zero
- Fixed by upgrading
- Yes
Solution
Upgrade to version 0.8.4.1.
Vulnerable code sample
import os
from flask import Flask, request, send_file
app = Flask(__name__)
@app.route('/image_get')
def image_get():
path = request.args.get('path')
# Vulnerable code - no sanitization of the path
filepath = os.path.join('/var/www/images', path)
try:
return send_file(filepath, mimetype='image/png')
except FileNotFoundError:
return "File not found", 404
if __name__ == '__main__':
app.run(debug=True)Patched code sample
import os
def image_get_fixed(base_path, requested_path):
"""
Retrieves an image file, preventing path traversal vulnerabilities.
Args:
base_path: The allowed base directory for image files.
requested_path: The path to the image file requested by the user.
Returns:
The content of the image file as bytes, or None if the file is not found
or the requested path is invalid.
"""
# Sanitize the requested path by removing any leading slashes and normalizing the path
safe_path = os.path.normpath(requested_path)
# Create the absolute path by joining the base path and the sanitized path
absolute_path = os.path.abspath(os.path.join(base_path, safe_path))
# Check if the absolute path is within the allowed base path. Crucial security check!
if not absolute_path.startswith(os.path.abspath(base_path)):
print("Attempted path traversal!")
return None # Or raise an exception
try:
with open(absolute_path, 'rb') as f: # Open in binary mode for images
image_data = f.read()
return image_data
except FileNotFoundError:
print(f"File not found: {absolute_path}")
return None
except Exception as e:
print(f"Error reading file: {e}")
return None
if __name__ == '__main__':
# Example usage (replace with your actual base path)
base_image_dir = "/path/to/your/image/directory" # IMPORTANT: Set this to a safe directory
os.makedirs(base_image_dir, exist_ok=True) #Creates the directory if it doesn't exist
# Create a test image file (for demonstration)
test_image_path = os.path.join(base_image_dir, "test_image.png")
with open(test_image_path, "wb") as f:
f.write(b"This is a dummy image file.")
# Example 1: Valid request
image_data = image_get_fixed(base_image_dir, "test_image.png")
if image_data:
print("Image data retrieved successfully.")
# Example 2: Path traversal attempt
image_data = image_get_fixed(base_image_dir, "../../../../../etc/passwd") # Simulate attack
if image_data is None:
print("Path traversal attempt prevented.")
#Example 3: Traversal inside the base directory, but still avoids going outside
os.makedirs(os.path.join(base_image_dir, "images"), exist_ok=True)
image_data = image_get_fixed(base_image_dir, "images/../test_image.png")
if image_data:
print("Image data retrieved successfully (directory traversal inside base allowed)")Payload
../../../../../../../../etc/passwd
Cite this entry
@misc{vaitp:cve20256166,
title = {{Agent-Zero <= 0.8.4 path traversal in image_get.py via path argument.
}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2025},
note = {VAITP Python Vulnerability Dataset, entry CVE-2025-6166},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-6166/}}
}
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 ::
