NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · LlamaIndex

CVE-2024-23751: SQL injection in llama-index

criticalCVSS 3.1 9.8GHSA-2jxw-4hm4-6w87

LlamaIndex (llama-index) up to 0.9.35 runs SQL generated by an LLM from natural language with no safety checks in its Text-to-SQL query engines. A crafted prompt can make the model emit a DROP TABLE or other write statement that the engine executes. The advisory lists no patched version, and the maintainers treat this as a user-side safety duty.

Published Jan 22, 2024 · Updated Jan 29, 2024 · Analysis Nov 2, 2026

What an attacker can do

The Text-to-SQL components NLSQLTableQueryEngine, SQLTableRetrieverQueryEngine, NLSQLRetriever, RetrieverQueryEngine and PGVectorSQLQueryEngine ask an LLM to turn a question into SQL, then run it. The run_sql step only checks that the SQL is valid, not that it is safe. A prompt that tells the model to drop a table produces SQL that does so. The reporter's proof of concept, on v0.9.28.post2, dropped a table called city_stats.

The attacker needs access to whatever input reaches the engine, such as a chat box or API in front of a database. They then get whatever the database account permits: reading any table it can see, changing or deleting rows, and dropping tables. The CVSS vector rates network, no privileges and high impact on all three areas. The real limit is the permissions of the database user the app connects with.

The maintainers argue that Text-to-SQL always carries this risk and that developers must use it safely. They closed the issue as not planned.

Who is affected

llama-index up to and including 0.9.35 when you use any of the five Text-to-SQL classes against a database. The GitHub issue shows the maintainers did not close the underlying behavior in later versions. Treat any version of these classes as risky unless the database account is locked down.

Check the installed version:

pip show llama-index

Search for the classes:

grep -rnE "NLSQLTableQueryEngine|SQLTableRetrieverQueryEngine|NLSQLRetriever|PGVectorSQLQueryEngine" .

llama-index

Ecosystem
PyPI
Affected
<= 0.9.35
Fixed in
No patched version yet
Check
pip show llama-index

How to fix it

There is no patched version. The advisory lists none, and the issue thread does not confirm a SELECT-only restriction was added.

The mitigations discussed in the issue are:

  • Connect with a read-only database user.
  • Expose only specific tables or views.
  • Restrict the generated SQL to SELECT statements.
  • Limit who can use the feature.

The database account is the control that holds. Do not give the Text-to-SQL engine a user that can write or drop.

How to tell if you were hit

Check database logs for statements you did not expect from the application's database user, especially DROP, DELETE, UPDATE, INSERT or ALTER. Compare the statements with the questions users sent to the app. Failed permission errors on write statements are a sign that someone tried and that your read-only setup worked. Keep application logs of the generated SQL so you can audit it.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

LlamaIndex (aka llama_index) through 0.9.35 allows SQL injection via the Text-to-SQL feature in NLSQLTableQueryEngine, SQLTableRetrieverQueryEngine, NLSQLRetriever, RetrieverQueryEngine, and PGVectorSQLQueryEngine. For example, an attacker might be able to delete this year's student records via "Drop the Students table" within English language input.

Questions

Is there a fixed version of llama-index for CVE-2024-23751?

No fixed version is listed. The maintainers said the likely approach is SELECT-only queries plus views or roles, but the issue was closed as not planned and a fix is not confirmed.

Does a read-only database user stop it?

It stops destructive statements such as DROP TABLE, because the database refuses them. The model can still run any SELECT the user may run, so limit tables and views as well.

Is this exploited in the wild?

The sources I read do not say so. The issue contains a proof of concept that dropped a table.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More LlamaIndex vulnerabilities

All LlamaIndex entries