What is prompt injection?
Prompt injection is a vulnerability in applications built on language models: text from a user, or from content the model reads, is treated as instructions and overrides the developer's. The model receives its rules and the untrusted text as one sequence, with no boundary it enforces, so attacker-written words can change what it says or does.
Part of the roadmap: Stage 7, Choose a direction
Why it matters
OWASP ranks it first, LLM01, in its Top 10 for LLM applications, and splits it in two. Direct injection is typed into the chat box. Indirect injection hides in something the model reads on the user's behalf, such as a web page, an email, a document or a product review, so the person attacked never sees it.
It matters more as apps give models more reach. A bot that only chats can leak what is in its prompt or tell a customer something false. A bot that renders Markdown, browses or calls tools can send data out or take actions, and then the injected text acts with the app's permissions. Simon Willison, who named it in 2022, called it a security exploit because apps build prompts by joining their own instructions to untrusted input.
Example: a support bot that was told to keep a secret
CyberGym, the legal practice target, has a support chatbot, but it is a classic intent classifier with canned answers, not a language model, so there is nothing to inject into. The lab for this bug class is a model you run yourself. In ours, a toy support bot on two small local models was told never to reveal a staff discount code, and printed it with its whole system prompt in 10 out of 10 runs on each model when asked to repeat the text above.
The lesson is that the model's own rules do not hold. On your own app (https://your-app.example), put the controls in the code around the model, where an attacker's wording cannot reach them:
# Keep secrets out of the prompt; check the reply in code before it is shown
reply = model.generate(system=RULES, user=message)
if any(s in reply.upper().replace(" ", "") for s in SECRETS):
reply = "Sorry, I can't help with that."
Then test the bot as an attacker would, on a build you own: ask it to repeat its instructions, hide an instruction in a document it summarises, and see whether it renders an image or link to a host you did not list. Each one that works is a finding about the code around the model.
Common mistakes
- Telling the model to ignore instructions in the data. It is one more instruction the attacker can argue with. Enforce limits in code.
- Putting secrets or keys in the system prompt. Anything in the prompt can leak. Give the bot a tool that checks the value instead.
- Rendering the model's Markdown as it comes. An image URL can carry data to another host. Allow only hosts you list, or show plain text.
- Letting the model act without a gate. Once it can call tools, check each call against a policy and ask the user for anything that matters.
Related terms
Go deeper
Sources
Test only sites you own or have written permission to test. To practise without one, use CyberGym, a legal, deliberately vulnerable target. Practise on CyberGym.
