Summary
QWED passes caller-controlled mathematical expressions to SymPy's parse_expr() without restricting the namespaces available during evaluation. An attacker with a valid tenant API key, including one obtained through an enabled self-service signup flow, may execute arbitrary Python code in the API server process through the math or batch verification endpoints.
Affected context
The vulnerability occurs in QWED deployments that expose the math verification or batch verification APIs and use the affected expression-processing behavior. It becomes risky when an attacker can obtain a tenant API key and submit expressions that reach parse_expr() without strict parsing, validation, or restricted global and local namespaces.
Exploit preconditions
- Attack surface: Network-accessible QWED verification API
- Required access: A valid tenant API key; the default signup flow may allow an attacker to create a standard tenant account and obtain one
- Trigger point: Submission of caller-controlled input to the math verification endpoint or a batch item processed as a math verification request
- Why exploitation is possible: Expressions are passed to a Python-backed evaluator without restricted namespaces, allowing evaluation behavior to resolve builtins and execute code in the API server process
Why this happens
The underlying bug is code injection caused by treating untrusted mathematical expressions as executable Python-like input. QWED invokes SymPy parse_expr() without constrained global_dict and local_dict namespaces, while its normalization step does not provide meaningful security validation. This maps to CWE-94: Improper Control of Generation of Code, because attacker-controlled data can influence code evaluation and execution.
Potential impact
- Arbitrary Python or operating system command execution in the API server process
- Reading, modifying, or deleting application and host-accessible files
- Modification or poisoning of tenant and application data
- Service termination or denial of service
- Compromise of other tenants in a shared deployment
- Exposure of credentials and other sensitive runtime information
General mitigation guidance
Mitigation generally focuses on preventing untrusted expressions from reaching general-purpose evaluators.
Common defensive patterns include:
- Replace dynamic expression evaluation with a purpose-built mathematical parser or an allowlisted expression language
- Use strictly restricted namespaces and disable access to builtins when symbolic parsing is unavoidable
- Validate expressions against an explicit grammar and permitted operation set before parsing
- Apply the same controls consistently to individual and batch verification paths
- Treat tenant-supplied input as untrusted regardless of API-key validity
- Disable or tightly control self-service account and API-key issuance where it is not required
- Run the API with least-privilege service accounts, isolated credentials, and restricted filesystem access
- Enforce tenant isolation and network segmentation to limit cross-tenant impact
How teams detect issues like this
Organizations can identify related risks through:
- Static analysis rules for
eval(), unrestricted SymPyparse_expr(), and dynamic parser calls lacking constrained namespaces - Code review checks for caller-controlled expressions reaching interpreters or symbolic evaluators
- Data-flow analysis tracing API fields and batch items into expression-processing functions
- Policy enforcement that requires approved parsers and explicit allowlists for executable input
- Runtime monitoring for unusual verification requests, process spawning, file access, or unexpected outbound connections from the API service
- Automated code review tools configured to flag dynamic evaluation and missing tenant-boundary controls

