Summary
Python StateMachine before version 3.2.0 unsafely evaluates SCXML <data expr="..."> attributes using Python's built-in eval() with attacker-controlled input.
A malicious SCXML document can cause arbitrary code execution in the hosting Python process whenever these expressions are processed.
Affected context
The vulnerability exists when Python StateMachine is used to process SCXML documents that may contain untrusted or partially trusted content.
It is especially relevant in systems where workflows, state machines, or automation rules are defined via SCXML uploaded by users, integrated from external services, or loaded from dynamically obtained sources.
The issue is triggered when <data expr="..."> attributes are interpreted as Python expressions and evaluated during state transitions or data updates without isolation or prior validation.
Exploit preconditions
- Attack surface: SCXML parsing and execution interface in applications using Python StateMachine
- Required access: Ability to supply or influence SCXML content (e.g., upload, configuration, API input, or external file inclusion)
- Trigger point: Processing of
<data expr="...">elements where theexprattribute is evaluated - Why exploitation is possible: The SCXMLProcessor passes attacker-controlled expression strings through a call chain that ultimately invokes Python's
eval()directly, with access to the process context and without sandboxing, whitelisting, or expression restrictions
Why this happens
This vulnerability stems from treating SCXML expression attributes as trusted Python code and evaluating them with eval() in the main interpreter context.
This pattern aligns with CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection'), where input intended as data is instead executed as code.
The SCXMLProcessor design couples user-supplied SCXML expressions directly to dynamic evaluation, lacking a safe expression language, contextual escaping, or a controlled execution environment.
Potential impact
- Execution of arbitrary Python code within the hosting application process
- Reading, modifying, or deleting data accessible to the application
- Installation of backdoors or execution of arbitrary OS-level commands via Python APIs
- Compromise of application integrity and potential pivot to other systems or services the application can reach
General mitigation guidance
Effective mitigation focuses on removing or strictly controlling dynamic code evaluation driven by SCXML content.
Common patterns include:
- Replacing
eval()with a constrained, domain-specific expression language or a safe evaluation engine that cannot execute arbitrary Python code - Restricting SCXML inputs to trusted sources and treating user-supplied SCXML as data, not executable logic
- Implementing allowlisted operations and explicit mapping between SCXML expressions and predefined functions or actions
- Running state machine processing under least-privilege principles, minimizing accessible system resources and credentials
- Introducing configuration options that disable dynamic expression evaluation when not required
How teams detect issues like this
Detection generally relies on both code-level analysis and runtime controls:
- Static analysis rules that flag usage of
eval()and similar dynamic execution functions in SCXML processing paths - Code review checklists that require scrutiny whenever user-controlled strings influence code execution or expression evaluation
- Security-focused linting or automated review tools configured to detect eval-style patterns and untrusted data flows into interpreters
- Runtime instrumentation or logging that highlights unexpected or complex SCXML expressions, enabling anomaly detection and incident investigation

