Summary
The OpenStack Vitrage query parser performs dynamic code evaluation in _create_query_function, allowing a user with API access to trigger code execution on the Vitrage service host.
When an attacker can supply crafted query input to the Vitrage API, they may execute arbitrary code as the Vitrage service user, potentially leading to full compromise of the host and the Vitrage service.
Affected context
This vulnerability affects OpenStack Vitrage deployments that:
- Expose the Vitrage API to users or integrated services
- Use the vulnerable query parser implementation in
vitrage/graph/query.py - Allow tenants, operators, or automated components to submit queries to Vitrage
The issue is triggered when user-controlled query input is transformed into executable code in _create_query_function, without sufficient sanitization or isolation.
Exploit preconditions
- Attack surface: Network-exposed Vitrage API endpoint, typically within an OpenStack control or management plane.
- Required access: Ability to authenticate to, or otherwise reach, the Vitrage API and submit queries (e.g., as a tenant, operator, or via a compromised service account).
- Trigger point: Submission of a specially crafted query string that is processed by
_create_query_functioninvitrage/graph/query.py. - Why exploitation is possible: The query parser dynamically evaluates query expressions derived from user input, effectively treating untrusted data as code, enabling arbitrary code execution in the context of the Vitrage service process.
Why this happens
The root cause is the use of dynamic code evaluation constructs on data derived from user-controlled query parameters.
In _create_query_function, query expressions are converted into executable Python code or function objects without strong separation between data and logic.
This aligns with CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection'), where user-controlled input is incorporated into code that is then interpreted or executed by the runtime.
The lack of robust input neutralization, whitelisting of allowed operations, or use of a non–Turing-complete query language means that crafted input can escape intended constraints and invoke arbitrary code paths.
Potential impact
- Execution of arbitrary Python code on the Vitrage service host as the Vitrage service account
- Unauthorized access to Vitrage configuration, credentials, or in-memory secrets
- Lateral movement from the Vitrage host to other OpenStack services or infrastructure components
- Tampering with Vitrage alarms, root-cause analyses, or topology data to hide or stage further attacks
- Denial of service of the Vitrage service or instability of the OpenStack control plane
General mitigation guidance
Mitigation generally involves eliminating dynamic interpretation of user input and constraining the query language to data-only constructs.
Recommended defensive patterns include:
- Replacing dynamic evaluation (e.g., eval-like constructs) with a dedicated, declarative query engine that treats queries as data structures rather than code.
- Implementing strict parsing with an explicit grammar and AST, rejecting any tokens or operators outside a controlled whitelist.
- Normalizing and validating query parameters early, ensuring only safe fields, operators, and literal types are accepted.
- Executing query handling under least privilege, ensuring the Vitrage service account has minimal access on the host and to other services.
- Introducing defense-in-depth controls (e.g., seccomp, containers, or sandboxing) around services that must process user-controlled expressions.
How teams detect issues like this
Effective detection combines code-centric review with runtime monitoring:
- Static analysis: Configure rules to flag use of generic dynamic evaluation APIs (e.g., eval, exec, dynamic compilation) when they operate on or concatenate user-controlled input.
- Code review: Require manual inspection of query parsing and expression-building logic, looking for patterns where input strings are transformed directly into code or lambdas.
- Policy enforcement: Establish coding standards that prohibit dynamic evaluation of user input and enforce their adoption via pre-commit hooks or CI checks.
- Runtime monitoring: Track unusual behavior from the Vitrage service process, such as unexpected subprocess creation, file system access, or outbound network connections, which may indicate exploitation attempts.
- Automated tools: Use SAST/IAST tools configured with rules for eval injection and dynamic code execution, integrated into the development and deployment pipelines.

