Summary
Sinaptik AI PandasAI versions up to 0.1.4 contain a SQL injection vulnerability in multiple query and document management functions within the pandasai-lancedb extension.
When untrusted input is interpolated into database queries without proper sanitization or parameterization, a remote attacker may manipulate or execute arbitrary SQL statements against the underlying LanceDB-backed datastore.
Affected context
This issue occurs in the pandasai-lancedb extension of PandasAI, specifically in the lancedb.py module under extensions/ee/vectorstores/lancedb/pandasai_lancedb/.
The vulnerable functions include:
delete_question_and_answersdelete_docsupdate_question_answerupdate_docsget_relevant_question_answers_by_idget_relevant_docs_by_id
The risk is present when these functions construct database queries with user-controlled identifiers, filters, or document metadata, especially in deployments where PandasAI is exposed through APIs, web backends, agents, or other remotely accessible services.
Exploit preconditions
- Attack surface: Any API endpoint, web handler, or service method that routes unvalidated client input into the affected LanceDB-related functions.
- Required access: Ability to send requests that influence question IDs, document IDs, filters, or other query parameters consumed by the vulnerable functions; no prior authentication may be required depending on the surrounding application.
- Trigger point: Execution of a database operation (delete, update, or retrieval) where input is concatenated into the query string or otherwise bound without strict parameterization.
- Why exploitation is possible: The code path appears to construct LanceDB or SQL-like queries directly from untrusted values without using safe parameter binding, canonicalization, or robust input validation, aligning with CWE-89 and CWE-74 patterns.
Why this happens
The root cause is unsafe construction of database queries using untrusted input in the pandasai-lancedb extension.
Instead of relying on parameterized queries or a type-safe query builder, the implementation likely interpolates IDs, conditions, or document attributes into query expressions as raw strings.
This behavior matches:
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') — untrusted input is embedded into commands interpreted by a database engine.
- CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component — the downstream component (LanceDB / query engine) consumes data that has not been neutralized for its context.
As a result, crafted input can break out of the intended query structure and alter the semantics of delete, update, or select operations.
Potential impact
- Reading data from tables or collections that the application logic does not intend to expose.
- Modifying or deleting stored questions, answers, and documents, potentially corrupting AI knowledge bases or vector stores.
- Bypassing application-level access controls by directly manipulating query predicates.
- Injecting conditions that cause denial of service, such as extremely expensive queries or broad destructive operations.
- In some environments, pivoting to compromise adjacent data or services that share the same database engine.
General mitigation guidance
Effective mitigation focuses on eliminating direct string-based query construction and tightening trust boundaries around query inputs:
- Prefer parameterized queries or prepared statements offered by the underlying LanceDB or database driver, ensuring that user-supplied values are always treated as data rather than executable query syntax.
- Introduce a constrained query-building API or repository layer that accepts only strongly-typed parameters (IDs, enums, whitelisted fields) and never raw fragments of query language.
- Apply strict input validation for IDs, limits, and filters, using allowlists for acceptable fields and operators instead of free-form expressions.
- Centralize authorization checks around delete/update operations so that even if input is malformed, it cannot bypass role- or tenant-based restrictions.
- Run database and application components with least-privilege accounts, limiting what an injected query is allowed to do if a flaw is reached.
How teams detect issues like this
Detection typically combines code-level analysis with runtime monitoring:
- Static analysis: Configure SAST rules to flag string concatenation or f-string formatting used to build queries in
lancedb.pyand related data-access modules. Look specifically for patterns where user-controlled parameters flow into query constructors. - Code review: During reviews, require that all database interactions use parameterized APIs; add checklist items focused on query construction in extensions and vector store integrations.
- Policy enforcement: Introduce linters or CI checks that forbid direct use of low-level query execution functions with raw strings, except in explicitly reviewed and annotated locations.
- Runtime monitoring: Enable database query logging and anomaly detection to identify unexpected query patterns, overly broad deletions/updates, or queries containing attacker-controlled substrings.

