CVE-2026-55546
Arbitrary code execution via unfiltered SymPy expression parsing in verify_math_expression().
- CVSS 9.8
- CWE-94
- Input Validation and Sanitization
- Remote
QWED-MCP is a deterministic verification gateway for MCP. Prior to 0.2.1, verify_math_expression() in src/qwed_mcp/engines/math_engine.py passes attacker-controlled expression and claimed_result strings directly to SymPy's parse_expr() after only normalizing caret syntax to Python exponent syntax, without restricting global_dict, removing Python built-ins, or validating the expression AST. Because parse_expr() calls Python's eval() with built-ins available, an attacker who can cause a downstream caller to pass untrusted input to this public library function can use Python import functionality to execute arbitrary operating-system commands as the qwed-mcp process user, read or modify accessible data, exfiltrate process secrets, or reach internal services. The default MCP tool registry does not expose verify_math_expression(), so exploitation requires a downstream integration that invokes the library API with attacker-controlled input. This issue is fixed in version 0.2.1.
- CWE
- CWE-94
- CVSS base score
- 9.8
- Published
- 2026-08-25
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- QWED-MCP
- Fixed by upgrading
- Yes
Solution
Upgrade QWED-MCP to version 0.2.1 or later.
Vulnerable code sample
import re
from sympy import parse_expr
def verify_math_expression(expression: str, claimed_result: str) -> bool:
"""
Verify that the given mathematical expression evaluates to the claimed result.
The expression may use '^' for exponentiation which is normalized to '**'.
"""
# Normalise caret syntax
expr = expression.replace('^', '**')
# VULNERABLE: passing attacker-controlled strings to parse_expr without restrictions
parsed = parse_expr(expr, evaluate=False)
try:
result = parsed.evalf()
claimed = parse_expr(claimed_result, evaluate=False).evalf()
return result == claimed
except Exception:
return FalsePatched code sample
import re
from sympy import parse_expr
from sympy.parsing.sympy_parser import standard_transformations, implicit_multiplication_application, convert_xor
# FIX: restrict globals and remove builtins during parsing
SAFE_TRANSFORMS = standard_transformations + (implicit_multiplication_application, convert_xor)
def verify_math_expression(expression: str, claimed_result: str) -> bool:
"""
Verify that the given mathematical expression evaluates to the claimed result.
The expression may use '^' for exponentiation which is normalized to '**'.
"""
# Normalise caret syntax
expr = expression.replace('^', '**')
# Use safe parsing with no globals and limited transformations
parsed = parse_expr(expr, evaluate=False, transformations=SAFE_TRANSFORMS, global_dict={}, local_dict={})
try:
result = parsed.evalf()
claimed = parse_expr(claimed_result, evaluate=False, transformations=SAFE_TRANSFORMS, global_dict={}, local_dict={}).evalf()
return result == claimed
except Exception:
return FalsePublished fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- fix(security): restrict sympy parse_expr to prevent code execution (CWE-94) (QWED-AI/qwed-mcp)
src/qwed_mcp/engines/math_engine.py,src/qwed_mcp/engines/math_engine.py · verify_math_expression
Cite this entry
@misc{vaitp:cve202655546,
title = {{Arbitrary code execution via unfiltered SymPy expression parsing in verify_math_expression().}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-55546},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-55546/}}
}
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 ::
