CVE-2025-5321
Aim up to 3.29.1 query.py RPO sandbox issue via Query arg manipulation.
- CVSS 5.3
- CWE-264
- Design Defects
- Remote
A vulnerability classified as critical was found in aimhubio aim up to 3.29.1. This vulnerability affects the function RestrictedPythonQuery of the file /aim/storage/query.py of the component run_view Object Handler. The manipulation of the argument Query leads to sandbox issue. The attack can be initiated remotely. The exploit has been disclosed to the public and may be used. The vendor was contacted early about this disclosure but did not respond in any way.
- CWE
- CWE-264
- CVSS base score
- 5.3
- Published
- 2025-05-29
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Functionality
- Category
- Design Defects
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- aimhubio aim
- Fixed by upgrading
- Yes
Solution
Upgrade to a version greater than 3.29.1, if available. If not, patch the vulnerability manually or discontinue use.
Vulnerable code sample
# Hypothetical vulnerable code based on CVE-2025-5321 description
# This is an illustrative example and might not perfectly reflect the actual vulnerability
import RestrictedPython
from RestrictedPython import compile_restricted
def RestrictedPythonQuery(query):
"""
Executes a restricted Python query.
Args:
query: The Python query string to execute.
"""
try:
# Prior to the fix, the restricted environment might have been configured
# inadequately, allowing for sandbox escape. This is a *SIMPLIFIED*
# representation. The actual vulnerability likely involved more subtle bypasses.
byte_code = compile_restricted(query)
# The 'globals' dict is not sufficiently sandboxed
exec(byte_code, globals())
except Exception as e:
print(f"Error executing query: {e}")
# Example usage (potentially vulnerable)
if __name__ == '__main__':
# User-supplied query (from a remote source, potentially)
user_query = input("Enter your query: ")
RestrictedPythonQuery(user_query)Patched code sample
# This is a hypothetical fix as the exact fix for CVE-2025-5321 is not publicly available.
# This example demonstrates a strengthened validation and sanitization of the query string
# to prevent code injection within the RestrictedPython environment.
import ast
import restrictedpython
def safe_eval(query):
"""
Safely evaluates a query string using RestrictedPython with enhanced validation.
Args:
query: The query string to evaluate.
Returns:
The result of the evaluation, or None if the query is invalid.
"""
# 1. Validate the query syntax using ast.parse to prevent injection of arbitrary code structures.
try:
tree = ast.parse(query)
# Check for potentially dangerous AST nodes. This is just an example, you might need
# a more comprehensive check depending on the specifics of the RestrictedPython usage.
for node in ast.walk(tree):
if isinstance(node, (ast.Import, ast.ImportFrom, ast.Call)):
raise ValueError("Invalid query: Imports and function calls are not allowed.") # or log, or handle it differently
except SyntaxError as e:
print(f"Syntax error in query: {e}")
return None
except ValueError as e:
print(f"Invalid query: {e}")
return None
# 2. Sanitize the query string (Example: Allow only specific characters/patterns)
# This is highly dependent on the expected structure of the query. Adapt as needed.
allowed_chars = "0123456789.+-*/()x" # Example: Allow numbers, operators, 'x' (variable)
sanitized_query = "".join(c for c in query if c in allowed_chars)
if sanitized_query != query:
print("Query sanitized: Removed disallowed characters.")
# Decide whether to proceed with the sanitized query or reject it.
# For increased security, it's often safer to reject if sanitization was needed.
# For this example, we will proceed using the sanitized query.
query = sanitized_query
# 3. Execute the sanitized and validated query within the RestrictedPython environment.
# (RestrictedPython setup is not shown, assume it is configured elsewhere)
# Assume `safe_globals` is defined and contains the allowed variables and functions.
safe_globals = {'x': 10} # Example: Allow only variable 'x'
safe_locals = {}
try:
compiled_code = compile(sanitized_query, '<string>', 'eval')
result = eval(compiled_code, safe_globals, safe_locals) #Use built-in eval in RestrictedPython
return result
except Exception as e:
print(f"Error during evaluation: {e}")
return None
def RestrictedPythonQuery(Query):
"""
The function that uses safe_eval to process user queries.
"""
result = safe_eval(Query)
return result
# Example Usage:
#Potentially dangerous query
#print(RestrictedPythonQuery("__import__('os').system('rm -rf /')")) # This should be blocked by the validation.
#Safe Query
print(RestrictedPythonQuery("x + 5"))
#Query with not allowed characters (will be sanitized)
print(RestrictedPythonQuery("x + 5;import os"))Payload
__import__('os').system('cat /etc/passwd')
Cite this entry
@misc{vaitp:cve20255321,
title = {{Aim up to 3.29.1 query.py RPO sandbox issue via Query arg manipulation.
}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2025},
note = {VAITP Python Vulnerability Dataset, entry CVE-2025-5321},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-5321/}}
}
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 ::
