Severity:

HIGH RISK

(7.3)

SQL Injection in vanna-ai BigQuery Vector

CVE-2026-4229

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-74, CWE-89

Impact:

Unauthorized Data Access and Modification via SQL Injection

Severity:

HIGH RISK

(7.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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_data with externally supplied ID values.
  • Required access: Ability to send requests or trigger operations that pass attacker-controlled data into the ID parameter (e.g., authenticated or unauthenticated API calls, depending on deployment).
  • Trigger point: Execution of the BigQuery query that contains the unsafely embedded ID value inside remove_training_data.
  • Why exploitation is possible: The ID parameter 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 ID into 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 ID without 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_data and observe whether crafted inputs affect SQL semantics.
  • Consider integrating automated secure code review tools into CI pipelines to enforce policies against unsafe SQL construction.

Sources

SourceLink
gist.github.comgist.github.com/YLChen-007/b4f326eaecc29b192cf93dc5d6bc0623
vuldb.comvuldb.com/?ctiid.351152
vuldb.comvuldb.com/?id.351152
vuldb.comvuldb.com/?submit.771214

Frequently asked

questions

Exploitability depends on how remove_training_data is exposed. If it is reachable through a network-facing API that accepts untrusted ID values, a remote attacker can often exploit it. If access is limited to internal tools or trusted automation, the practical risk surface is smaller but still present.

That depends on the surrounding application. The vulnerability itself does not require elevated database privileges, but the attacker must be able to influence the ID argument. In many deployments this may require valid application credentials, while in others it may be accessible without authentication.

The most robust fix is to replace any string-based query construction with parameterized queries or prepared statements, ensuring that the ID value is always treated as data rather than SQL code. Complement this with strict validation of inputs and a centralized, well-reviewed data access layer.

Prevention involves both process and technical controls: adopt a project-wide rule that prohibits manual string concatenation for SQL, enforce this via code review and static analysis, provide developers with safe query-building utilities, and limit database privileges so that, even if a mistake occurs, the blast radius of an injection is reduced.

Find out what's already
exploitable in your codebase.