Summary
vanna-ai up to version 2.0.2 contains a SQL injection vulnerability in the remove_training_data function of google/bigquery_vector.py, where the ID argument is unsafely incorporated into a query.
A remote attacker who can influence the ID parameter may craft malicious input that alters the intended SQL command, potentially leading to unauthorized data access or modification in the backing BigQuery dataset.
Affected context
The vulnerability occurs in deployments of vanna-ai (up to 2.0.2) that use the legacy BigQuery vector backend and invoke remove_training_data with an ID value originating from user-controllable or otherwise untrusted sources.
The issue manifests when the code constructs SQL statements by directly interpolating the ID argument into query strings rather than using parameterized or prepared statements.
Environments that expose this functionality through APIs, web services, or other remote interfaces are particularly at risk.
Exploit preconditions
- Attack surface: Application interfaces (APIs, services, or integrations) that call
remove_training_datawith externally suppliedIDvalues. - Required access: Ability to send requests or trigger operations that pass attacker-controlled data into the
IDparameter (e.g., authenticated or unauthenticated API calls, depending on deployment). - Trigger point: Execution of the BigQuery query that contains the unsafely embedded
IDvalue insideremove_training_data. - Why exploitation is possible: The
IDparameter is incorporated into SQL without proper parameterization or escaping, allowing crafted input to break out of the intended query structure and inject additional SQL clauses or statements.
Why this happens
The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), and is also related to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
In the affected code, the ID argument is treated as trusted and concatenated or formatted directly into a SQL string destined for BigQuery.
This pattern fails to neutralize characters with special meaning in SQL (such as quotes, separators, or operators), allowing user-controlled data to be interpreted as part of the command rather than as a data value.
The vulnerability is fundamentally a design flaw in query construction, where data and code are not cleanly separated through parameterization or a safe query builder.
Potential impact
- Attackers may modify or delete training data records associated with vanna-ai, beyond those they are intended to affect.
- Attackers could read sensitive data stored in the same BigQuery dataset or related tables, if permissions allow.
- Malicious queries may alter model-related metadata, potentially degrading model performance or corrupting training corpora.
- In misconfigured environments, injected SQL could impact additional schemas or datasets accessible to the BigQuery service account.
- Application reliability can be affected, leading to unexpected failures or data inconsistencies when harmful queries succeed.
General mitigation guidance
Effective mitigation focuses on ensuring that SQL is constructed using safe patterns and that untrusted data is never treated as part of the command structure:
- Use parameterized queries or prepared statements whenever passing values such as
IDinto SQL, letting the database client library handle escaping and typing. - Introduce a dedicated data access layer or query builder that enforces separation of query templates from runtime values.
- Apply strict validation and normalization on identifiers used in queries (e.g., checking format, length, and character sets) before they reach the data access layer.
- Limit the privileges of the BigQuery service account so that it can only access specific datasets and operations required by vanna-ai.
- Adopt secure-by-default coding guidelines for data access, discouraging string concatenation for SQL in favor of vetted helper functions and ORM-like abstractions.
How teams detect issues like this
Detection typically combines code-centric review and runtime monitoring:
- Configure static analysis tools or linters to flag dynamic SQL construction patterns, particularly string concatenation or formatting involving external inputs passed to BigQuery client APIs.
- During code review, scrutinize all functions that build SQL statements, looking for interpolated variables, f-strings, or templates that include parameters such as
IDwithout parameterization. - Implement application-level logging that records query patterns (without logging sensitive data), and monitor for anomalous query shapes or unexpected clauses originating from user-driven operations.
- Use security testing (e.g., dynamic application security testing or manual penetration testing) to probe endpoints that invoke
remove_training_dataand observe whether crafted inputs affect SQL semantics. - Consider integrating automated secure code review tools into CI pipelines to enforce policies against unsafe SQL construction.

