SQL Injection Lab: break it, then fix it
This is a fake shop login. Behind it, the app glues your text into a database command (SQL). Watch the command change as you type. Your job: get in without knowing the password, then switch on the fix and see why it works.
🛒 TinyShop staff login
What the database receives
Your input is shown in yellow. Anything after -- is a comment, so the database ignores it.
Users table (normally secret)
Challenges
Hints (try first!)
- A single quote
'ends the text early. Try typing just'as the username. - For "any user": put
' OR '1'='1in the password box. - For admin: username
admin'--and anything as password. The--comments out the password check.
🎓 Why this matters for AI
SQL injection works because instructions (the SQL) and data (your input) are mixed in one string. The fix separates them.
LLMs have the same problem, but worse: the system prompt (instructions) and the user's text or a document (data) all go into one block of text. There is no parameterized query for LLMs yet. That's why prompt injection (week 6) is the #1 AI risk, and why we need layers of defense.