The Art Of Breaking Your Sql Powered Ai Chatbot After Building It
A chatbot that turns natural language into SQL and runs it against a SQLite database accepted raw SQL typed by the user, so the model passed it straight through to the database. An attacker could list every table and read the users table, including admin and customer details.
Hello Hackers!!! Ever wondered how AI chatbots with API and database access get compromised?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the AI-generated SQL was executed directly with no validation or parameterisation, and the model passed user-supplied SQL through unchanged.
Impact
An attacker could read the contents of the users table, including admin credentials and customer details, though the model's built-in safety blocked some malicious inputs.
What the attacker needed
Access to the chatbot interface; none
The fix
The bot should use parameterised queries, validate input, sanitise AI-generated SQL, give the chatbot a read-only database role and hide database errors; the text does not say it was fixed.
How it was found
- Send a simple SQL query to the chatbot and confirm it is accepted.
- Try a malicious query; the model's built-in safety blocks it.
- Ask the bot to list all tables in the database.
- Query the users table to extract admin and customer details.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The chatbot was built to translate plain questions into database commands. But it also accepted database commands typed directly by the user and ran them without checking. That let anyone ask the database to show its own list of tables and then read private user records.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.