Summary
SimpleEval's expression evaluation sandbox can inadvertently expose dangerous Python objects and modules via attributes of user-provided objects and callbacks.
Under certain conditions, an attacker who can supply expressions or influence the objects passed into SimpleEval may escape the intended sandbox and execute arbitrary code.
Affected context
This vulnerability affects Python applications that embed SimpleEval as a "safe" or sandboxed expression engine, particularly when:
- User-controlled or semi-trusted expressions are evaluated.
- Application objects are passed into SimpleEval as
namesor accessible values. - Callbacks or callable objects that can reach powerful APIs (e.g., OS, filesystem, networking, or import mechanisms) are exposed to evaluated expressions.
The risk increases when developers rely on SimpleEval as a primary security boundary for untrusted input rather than as a convenience expression engine.
Exploit preconditions
- Attack surface: Expression strings processed by SimpleEval (e.g., configuration expressions, filters, rules, or user-supplied formulas).
- Required access: Ability to influence or control the evaluated expression, and/or the objects and callbacks provided to the evaluator (directly or indirectly).
- Trigger point: Execution of a crafted expression through SimpleEval that navigates object attributes or uses callbacks to reach dangerous modules or functions.
- Why exploitation is possible: The sandbox design does not fully constrain attribute access on provided objects, nor does it reliably prevent callbacks from being used as conduits to powerful APIs. This allows traversal from "safe" entry points to unsafe objects inside the sandboxed environment.
Why this happens
The core issue stems from treating SimpleEval as a secure sandbox while allowing rich Python objects and callbacks to be passed in as evaluation context.
Internally, the evaluator permits attribute access on these objects and does not robustly enforce a strict allowlist of safe types and attributes.
This aligns with CWE-94: Improper Control of Generation of Code, because user-controllable expressions can drive execution paths that reach arbitrary, powerful functions.
It is also related to CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes, as user expressions can influence which attributes are accessed, inadvertently exposing dangerous modules or methods.
Potential impact
- Arbitrary Python code execution within the affected application process.
- Reading, modifying, or deleting local files accessible to the application.
- Network access using the application's privileges (e.g., data exfiltration or pivoting to internal services).
- Access to sensitive runtime data such as API keys, tokens, or secrets held in memory or environment variables.
- Full compromise of application integrity, including tampering with business logic or stored data.
General mitigation guidance
Effective mitigation focuses on treating expression evaluation as inherently risky and minimizing trust in user-provided expressions:
- Avoid using SimpleEval (or similar libraries) as a hard security boundary for untrusted users; place it behind additional access controls where possible.
- Pass only primitive, inert data structures (e.g., numbers, booleans, short strings) into the evaluator; avoid passing full objects, modules, or rich callables.
- Design the evaluation context around a strict allowlist: explicitly expose only the minimal set of safe functions and values needed by expressions.
- Prevent exposure of callbacks that can indirectly reach dangerous APIs, import mechanisms, or arbitrary attribute access.
- Apply the principle of least privilege at the process and container level (file-system access, network permissions, credentials) to limit impact if the sandbox is bypassed.
- Consider alternative designs that avoid dynamic evaluation for user-controlled input, such as declarative configuration or tightly constrained domain-specific languages.
How teams detect issues like this
Organizations can look for potential misuse of expression engines through a combination of static and review-based techniques:
- Static analysis and code search:
- Identify use of
SimpleEvaland similar evaluators across the codebase. - Flag call sites where untrusted or user-influenced data flows into expression parameters.
- Detect patterns where complex objects, modules, or functions are passed as
names,functions, or callbacks into the evaluator. - Code review signals:
- Any comments or documentation that describe SimpleEval as "secure", "sandboxed", or "safe for user input".
- Evaluation contexts that expose global application objects, database handles, HTTP clients, or direct OS interfaces.
- Expressions used in multi-tenant, plug-in, or user-rule scenarios without additional isolation.
- Policy and automated checks:
- CI policies that require justification when dynamic evaluation is introduced.
- Security linting rules to enforce a strict allowlist of safe helpers for SimpleEval or similar tools.
- Optional use of automated code scanning tools can help identify high-risk code evaluation patterns and data flows from user input into expression evaluators.

