Summary
SQLBot's Text-to-SQL chat interface in versions 1.7.0 and earlier concatenates user questions directly into LLM prompts and executes the returned SQL without validation.
An authenticated attacker can abuse prompt injection to coerce the LLM into producing arbitrary SQL, which is then executed against the backing database and, in PostgreSQL environments, can be escalated to remote code execution.
Affected context
This vulnerability affects deployments of SQLBot up to version 1.7.0 that:
- Expose the Text2SQL chat interface to authenticated users
- Use an LLM and RAG-based prompt pipeline where user questions are embedded directly in the system prompt
- Execute SQL statements produced by the LLM against a live database without applying validation, sanitization, or policy checks
- Are connected to relational databases, particularly PostgreSQL instances where SQL features like
COPY FROM PROGRAMare available
Exploit preconditions
- Attack surface: SQLBot Text2SQL chat endpoint or UI accessible to authenticated users
- Required access: Valid, authenticated SQLBot account with permission to use the Text2SQL feature
- Trigger point: Submission of a crafted "question" that includes prompt injection content directing the LLM to generate attacker-controlled SQL
- Why exploitation is possible:
- The user question is concatenated verbatim into the LLM prompt without escaping or constraints on intent
- The SQL extracted from the model's response is trusted as-is and executed against the database
- There is no server-side query validation, parameterization, or allowlist to restrict what SQL can be run
Why this happens
At its core, the issue is a classic CWE-89: Improper Neutralization of Special Elements used in an SQL Command, but mediated through an LLM-based Text2SQL layer.
The system treats natural language input as implicitly trustworthy instructions, embedding it directly into the system prompt. This enables prompt injection, where the attacker's text can override or subvert the intended instructions, causing the LLM to generate harmful SQL. Because the generated SQL is executed without parameterization, sanitization, or semantic validation, untrusted user influence extends all the way to raw SQL execution.
Architecturally, the bug is that the LLM is used as an authoritative query generator instead of a suggestion engine subject to strict server-side enforcement. This breaks the separation between user intent, model reasoning, and database execution, allowing user-controlled content to dictate executable SQL.
Potential impact
- Full read access to sensitive database tables the SQLBot service account can query
- Unauthorized modification or deletion of data, including bulk
UPDATE,INSERT, orDELETEoperations - Creation or alteration of database schemas, functions, or roles
- Abuse of PostgreSQL features (e.g.,
COPY FROM PROGRAM) to execute arbitrary OS commands on the database host - Lateral movement within the infrastructure if database-level RCE is achieved
- Corruption of analytics, reports, or business intelligence outputs that rely on the compromised data
General mitigation guidance
Effective mitigation revolves around re-establishing strict trust boundaries between user input, LLM output, and database execution:
- Treat LLM output as untrusted: Consider model-generated SQL as data requiring validation, not as authoritative instructions.
- Enforce query policies server-side:
- Implement allowlists for permissible operations (e.g.,
SELECT-only, no DDL, noCOPY, noEXECUTE, no unboundedUPDATE/DELETE). - Reject or strip statements containing dangerous keywords, multiple commands, or control structures.
- Use parameterization for user-supplied values: Ensure that user-specified filters, IDs, or search terms are always bound as parameters rather than interpolated into SQL text.
- Constrain the prompt design:
- Clearly delimit user-provided content in the prompt and avoid giving the model open-ended authority to run arbitrary SQL.
- Provide the model with explicit, machine-enforced constraints (e.g., a schema of allowed operations) and treat violations as errors.
- Limit database privileges: Run SQLBot with a dedicated, least-privilege database role that:
- Has read-only access where possible
- Is denied access to high-risk features like
COPY FROM PROGRAM,CREATE EXTENSION, or OS-level file access - Introduce an approval or dry-run mode: For higher-risk deployments, show generated SQL to users or operators for review before execution, or log and gate complex queries.
How teams detect issues like this
Detecting and monitoring for this class of vulnerability and its exploitation typically involves:
- Static analysis and code review:
- Look for code paths where LLM responses are parsed for SQL and then passed directly to database APIs.
- Flag flows where user input is appended or interpolated into prompts without sanitization or delimiting.
- Check for absence of query allowlists, SQL linting, or semantic validators around model-generated statements.
- Runtime query inspection:
- Enable database logging (e.g., PostgreSQL
log_statement) and monitor for unusual patterns such as: COPY FROM PROGRAMor other OS-interacting statements- DDL operations (
CREATE,ALTER,DROP) originating from the SQLBot service account - Multi-statement queries or unexpected transaction patterns
- Use anomaly detection on query shapes generated via the Text2SQL interface.
- Application-level monitoring:
- Log all LLM prompts and outputs associated with executed SQL, with appropriate privacy controls, to support forensic analysis.
- Add guardrails that reject or alert on queries exceeding complexity or resource usage thresholds.
- Policy enforcement in CI/CD:
- Apply secure coding policies for LLM-based components, requiring reviews for any automatic execution of model-generated code or queries.
- Optionally employ automated review tools that can trace tainted user input through prompt handlers to database execution points.

