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

CVE-2023-39660: pandasai vulnerable to prompt injection

highGHSA-w832-v3c6-m6rg

pandasai before 0.8.1 can be made to run attacker code by a crafted prompt. The library asks an LLM for Python and executes it, and its filter for dangerous code missed Python dunder attributes. A prompt-injection request to the prompt function reaches a shell. Upgrade pandasai to 0.8.1.

Published Aug 21, 2023 · Updated Nov 6, 2023 · Analysis Nov 2, 2026

What an attacker can do

pandasai turns a natural-language question about a dataframe into Python generated by an LLM, then runs that code with exec. Earlier fixes added a security check on the generated code, but it matched patterns and did not block dunder attributes such as __class__, __mro__, __subclasses__, __init__, __globals__ and __builtins__.

The reporter in issue 399 used a prompt that told the model to ignore prior instructions and return a chosen line of Python. The returned code listed every loaded class with ''.__class__.__mro__[-1].__subclasses__(), picked os._wrap_close by index, and reached __init__.__globals__['system'] to run ls. The index varies by Python version.

Anyone who can send a prompt to an application that exposes pandasai can try this, with no account if the app is public. The NVD text calls it a crafted request to the prompt function. The result is code execution as the application's user, with its files, secrets and network access. No CVSS score is recorded in this entry.

Who is affected

The pip package pandasai before 0.8.1; the CVE text names version 0.8.0 and earlier. Any app or notebook service that passes untrusted user text to pandasai is exposed. Check:

pip show pandasai

Then find where your code calls the library's run or prompt methods and who can reach them.

pandasai

Ecosystem
PyPI
Affected
< 0.8.1
Fixed in
0.8.1
Check
pip show pandasai

How to fix it

Upgrade pandasai to 0.8.1 or later:

pip install --upgrade "pandasai>=0.8.1"

The fix is pull request 409, merged on July 28, 2023. The issue thread says the maintainer proposed blocking dunder names that pandas code would not need. The thread also argues that pattern filtering alone is weak against jailbreaks, so run pandasai in a sandbox such as a locked-down container if users you do not trust can reach it.

How to tell if you were hit

Review stored prompts and the generated code the library logs for strings like __subclasses__, __mro__, __globals__, __builtins__ or system. Look for child processes started by the service that runs pandasai, and for outbound connections it should not make. Prompts that open with instructions such as ignoring what you were told earlier are a sign of an attempt.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

An issue in Gaberiele Venturi pandasai v.0.8.0 and before allows a remote attacker to execute arbitrary code via a crafted request to the prompt function.

Questions

Is this a prompt injection or a code injection?

Both. Prompt injection makes the model emit chosen Python, and the library then executes it. The CWE is code injection (CWE-94).

Which version fixes CVE-2023-39660?

pandasai 0.8.1, which includes pull request 409.

Does an LLM guardrail prevent this?

The reporter's prompt overrode the model's instructions. The thread argues pattern filtering of the generated code is not enough on its own.

Is it exploited in the wild?

The sources do not say so, and the entry has no CISA catalog data.

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 PandasAI vulnerabilities

All PandasAI entries