Summary
agno 2.6.5 contains a SQL injection vulnerability in the ClickHouse vector database backend where metadata filters are concatenated into queries using unsafe f-string interpolation.
By supplying crafted metadata keys and values to the delete_by_metadata() method, an attacker can inject arbitrary SQL expressions to manipulate or disclose data in the ClickHouse backend.
Affected context
This vulnerability appears in deployments using agno 2.6.5 with the ClickHouse vector database backend enabled and the delete_by_metadata() method exposed through an API, service layer, or application logic.
The issue manifests when metadata keys and values supplied by upstream callers are accepted without robust validation or parameterization and are passed to clickhousedb.py, where they are interpolated directly into SQL statements.
Systems that allow tenants, users, or external integrations to control metadata filters used for cleanup, retention policies, or record-specific deletions are particularly exposed.
Exploit preconditions
- Attack surface: Any endpoint, task, or internal service that calls delete_by_metadata() with user- or client-controlled metadata.
- Required access: Ability to supply or influence metadata keys and/or values (e.g., via HTTP API inputs, SDK parameters, or job configuration).
- Trigger point: Invocation of delete_by_metadata() in the ClickHouse backend, which builds SQL using f-strings in clickhousedb.py.
- Why exploitation is possible: Metadata fields are interpolated into SQL without proper escaping or parameterization, allowing attacker-controlled content to alter the intended query structure.
Why this happens
The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In the ClickHouse backend implementation (clickhousedb.py), delete_by_metadata() uses Python f-strings or similar string concatenation to embed metadata keys and values directly into SQL statements.
Because these values are not passed as bound parameters and are not rigorously sanitized, attacker-controlled input can inject additional SQL syntax, change WHERE clauses, or append new operations.
This pattern breaks the separation between data and code in database interactions, allowing the database server to interpret untrusted input as part of the executable query.
Potential impact
- Attackers may delete all rows from targeted ClickHouse tables by manipulating delete filters.
- Attackers could selectively delete or retain specific records, undermining data integrity and auditability.
- Error-based SQL injection may reveal schema details, table names, and column structure.
- Blind SQL injection techniques could be used to infer sensitive information from the database over time.
- Compromised metadata deletion logic may disrupt downstream analytics, search, or vector similarity operations relying on consistent datasets.
General mitigation guidance
Mitigation typically focuses on enforcing a strict separation between query structure and user-controlled data.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all metadata-driven SQL, ensuring metadata values are bound as parameters rather than interpolated into query strings.
- Restricting allowed metadata keys to a fixed, validated whitelist and mapping them to known column names instead of trusting arbitrary key names.
- Normalizing and validating metadata values according to expected types and formats (e.g., enums, integers, UUIDs) before passing them to the database layer.
- Centralizing query-building utilities to discourage ad hoc f-string or string-concatenation patterns for SQL.
- Applying least-privilege database roles so that even if a query is abused, the account cannot perform destructive operations beyond its intended scope.
How teams detect issues like this
Effective detection strategies for this class of vulnerability include:
- Static analysis rules that flag string-formatted SQL, especially f-strings or concatenation involving variables derived from request or metadata inputs.
- Code review checklists that require reviewers to confirm use of parameterized queries in all data access layers, particularly around delete or update operations.
- Logging and monitoring of unusual deletion patterns in ClickHouse, such as frequent full-table deletions or unexpected metadata filters, to identify potential abuse.
- Security tests and dynamic analysis (including fuzzing metadata inputs) to probe delete_by_metadata() and similar methods for injection behavior.
- Incorporating automated tooling in CI to enforce policies against unsafe query construction patterns in database adapters and backends.

