/

CVE-2026-30273

Severity:

HIGH RISK

(7.3)

SQL Injection in pandas-ai _execute_sql_query Component

CVE-2026-30273

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Execution / Data Compromise

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

pandas-ai v3.0.0 contains a SQL injection vulnerability in the pandasai.agent.base._execute_sql_query component, where user-controlled input is incorporated into SQL statements without sufficient safeguards.

In environments where the agent can be influenced by untrusted prompts or parameters, an attacker may be able to execute arbitrary SQL queries, leading to data exfiltration, tampering, or destructive operations on the underlying database.

Affected context

The vulnerability arises when pandas-ai is used to generate or execute SQL queries against a database, and the _execute_sql_query helper accepts values ultimately influenced by untrusted input (such as user prompts, parameters, or upstream application data).

This is most relevant in LLM-augmented analytics or agent workflows where natural language input can shape the final SQL string and where no strong parameterization or query whitelisting is enforced.

The issue is present in pandas-ai v3.0.0 and manifests wherever direct SQL strings are passed through _execute_sql_query without proper validation or binding.

Exploit preconditions

  • Attack surface: Any API, notebook, chat interface, or application that lets users influence SQL queries executed by pandas-ai.
  • Required access: Ability to supply or steer the input that flows into the agent logic (e.g., prompts, query text, or parameters).
  • Trigger point: Execution of _execute_sql_query with a SQL string that includes attacker-controlled fragments.
  • Why exploitation is possible: The component appears to build or accept a complete SQL string and pass it to the database driver without enforcing parameterized queries, robust escaping, or strict query templates, allowing hostile input to alter the intended SQL command structure.

Why this happens

This vulnerability is a classic example of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The _execute_sql_query routine likely treats SQL text as a simple string and either concatenates user- or model-influenced fragments into that string or accepts them without constraint.

Because the database engine interprets the final string as executable SQL, any embedded control characters (quotes, comment markers, statement separators, or injected clauses) can change the meaning of the query, bypass logical checks, or introduce additional commands.

The core insecure pattern is trusting dynamic SQL text instead of separating data from code via parameter binding or using constrained, predefined query templates.

Potential impact

  • Exposure of sensitive data through unauthorized SELECT queries.
  • Tampering with application data via injected INSERT, UPDATE, or DELETE statements.
  • Destructive operations such as dropping tables or truncating datasets, where database permissions allow.
  • Bypassing application-level business logic or authorization checks enforced at the query layer.
  • Pivoting to other systems if the database supports stored procedures or extended functions that reach beyond data access.

General mitigation guidance

Effective mitigation focuses on removing the ability for untrusted input to modify SQL control flow:

  • Prefer parameterized queries or bound variables instead of dynamically concatenating values into SQL strings, even for seemingly simple filters.
  • Introduce strict query templates or an allowed-query layer, where user or model inputs can only fill predetermined parameters (e.g., column filters, literal values) rather than arbitrary SQL fragments.
  • Apply schema-aware validation for any user-influenced values, restricting them to expected formats, enumerated sets, or strongly typed ranges before they reach the database layer.
  • Limit the agent's database access using least privilege, granting only those operations and schemas that are necessary for its intended analytics tasks.
  • Consider a query review or simulation mode in higher-risk contexts, where generated SQL is inspected or executed against a safe environment before touching production data.

How teams detect issues like this

Detection efforts can combine code-level analysis with runtime monitoring:

  • Use static analysis rules or linters to flag direct string concatenation or f-strings used to build SQL passed into _execute_sql_query or similar helpers.
  • During code review, look for places where prompts, user input, or LLM-generated text is treated as SQL without parameter binding or validation.
  • Implement database-level monitoring and logging to detect anomalous patterns, such as queries containing unexpected comments, UNION operations, or data definition language (DDL) statements in primarily read-only workflows.
  • Apply security policies in CI/CD pipelines that disallow the introduction of new dynamic SQL paths unless they demonstrate use of parameterized APIs.

Sources

SourceLink
gist.github.comgist.github.com/CafeD1/21c32edbf1b63fd88a79c290ed2a8059
github.comgithub.com/sinaptik-ai/pandas-ai

Frequently asked

questions

It can be, if the pandas-ai agent is exposed through a remote interface such as an API endpoint, chatbot, or notebook environment that accepts untrusted input. In that case, remote users may indirectly influence the SQL executed by _execute_sql_query.

An attacker needs the ability to supply or shape the input that ultimately affects the SQL query text—this could be a web form, a prompt to an AI assistant, or parameters in an analytics workflow. Direct database access is not required; the attack rides on the application's own connection.

The most robust fix is to refactor the SQL execution path to rely on parameterized queries or strongly typed bindings, and to restrict all user- or model-controlled data to parameters within predefined query templates rather than allowing free-form SQL text.

Establish a development standard that forbids dynamic SQL string construction from untrusted sources, enforce this via code review and automated checks, and design data-access layers that expose only parameterized operations. For AI/LLM-driven components, add an extra abstraction that converts model output into safe, structured query parameters instead of executing raw generated SQL.

Find out what's already
exploitable in your codebase.