Prompt injection is a critical attack class where text supplied by an attacker is interpreted as instructions rather than data by language models, exploiting the lack of separation between developer instructions and user input that exists in traditional programs. OWASP ranks it as the top risk for LLM applications because, unlike traditional code bugs, it reflects how language models fundamentally work and cannot be patched away. The article explains how prompt injection operates across multiple attack vectors, provides real-world examples that have been exploited against production systems, and details practical defenses that reduce rather than eliminate risk.
- Fundamental difference from traditional codeLanguage models receive developer instructions, conversation history, user messages, and fetched content as a single text stream with no structural separation. If any part reads like a newer or more specific instruction, the model may follow it. This is why prompt injection is treated as a class of weakness to manage rather than a bug to patch—the model is working as designed.
- Direct injection by application usersAttackers who are users of the chatbot type messages designed to make the model abandon its instructions. Common goals include revealing hidden system prompts, producing content the application refuses, or making the assistant act outside its intended role.
- Indirect injection through external contentAttackers place instructions in web pages, emails, PDFs, reviews, or code comments that the model will read. The actual victim is a person who asks the assistant to process that content, making any data source a potential attack vector. This form matters most in practice because it greatly expands attack surface.
- Hidden instructions in images and filesText can be embedded in image pixels, document metadata, or invisible characters that render invisibly on screen, allowing attackers to inject instructions through media models consume. The Microsoft 365 Copilot attack used invisible characters to exfiltrate stolen data through a link.
- Agent hijacking enables real-world harmWhen language models can call tools, injected instructions can send emails, read files, call APIs, or modify records using the agent's permissions. The damage ceiling is set by what permissions the agent was given, which led OWASP's 2026 list to rank Excessive Agency as third risk.
- Real attacks on production systemsBing Chat (2023) was compromised via hidden instructions in web pages; Microsoft 365 Copilot (2024) leaked data through shared documents with hidden instructions; ChatGPT's memory feature (2024) accepted false long-term memories from untrusted documents that shaped all future conversations. Each case followed the pattern: assistant read attacker-controlled content and had access to something valuable.
- Testing requires mapping inputs and outputsEffective testing follows the data flow rather than using clever phrases. Testers must map every input the model reads (user messages, retrieved documents, file uploads, tool results, memory), every tool the model can call and what it accesses, then systematically test whether text in each input can change behavior toward defined failures.
- No single defense eliminates injection riskDefenses include least privilege for tools, requiring human approval for risky actions, separating trusted from untrusted content, validating output before it reaches external systems, filtering known patterns, keeping secrets out of prompts, and logging unusual tool use. Each has limits; the governing principle is to ensure a successful injection has little valuable to reach.
Bottom line: Prompt injection cannot be fully fixed with current language models but can be substantially mitigated by designing systems so that even when injection succeeds, it accesses little of value—placing permission checks in code rather than relying on the model, and ensuring no single tool or action is valuable enough to attack without additional controls. Organizations building LLM applications must treat prompt injection as a system-level architectural concern, not a prompt-tuning problem.
Prompt injection is an attack where text that an AI model reads is treated as an instruction instead of as information. The model cannot reliably tell the difference between what its developer told it to do and what an attacker wrote into a message, a web page or a document. OWASP ranks it as the number one risk for applications built on large language models, and it has held that position in every edition of the list.
This guide explains how the attack works, the forms it takes, how to test for it in systems you are authorised to test, and which defences hold up. Each section links to a practice lab where you can see the behaviour on a live model.
Why prompt injection works
A traditional program keeps code and data apart. A database query has a fixed structure, and user input is passed in as a value. A language model has no such separation. Everything it receives arrives as one stream of text: the developer’s system prompt, the conversation so far, the user’s message, and anything the application fetched on the user’s behalf.
The model then predicts the most suitable reply to that whole stream. If part of the stream reads like a newer or more specific instruction, the model may follow it. The model is working as designed, which is why prompt injection is treated as a class of weakness to be managed, not a bug that one patch removes.
The main types of prompt injection
Direct prompt injection
The attacker types into the application themselves. They are a user of the chatbot, and they write a message meant to make the model set aside its instructions. The goals are usually to reveal hidden instructions, to produce content the application is meant to refuse, or to make the assistant act outside its role.
the sales bot prompt injection lab.
Indirect prompt injection
The attacker never talks to the model. They place instructions inside content the model will read later: a web page it summarises, an email it triages, a PDF it analyses, a product review, a code comment. The victim is the person who asks the assistant to process that content. This form matters most in practice, because it turns any data source into a possible attack path.
the indirect injection lab. Background reading: our tutorial on indirect prompt injection.
Injection through images and files
Models that accept images, audio or documents read instructions from those too. Text can be hidden in an image, in document metadata, or in characters a person cannot see on screen.
the visual prompt injection lab and the hidden character lab.
Injection against agents and tools
When a model can call tools, an injected instruction can do more than change words on a screen. It can send an email, read a file, call an API or change a record, using the permissions the agent was given. The damage is set by what the agent is allowed to do, which is why OWASP’s 2026 list moved Excessive Agency up to third place.
the agent hijack lab and the confused deputy lab.
Prompt injection and jailbreaking are different things
The two are often mixed up. Jailbreaking targets the model’s own safety training, to get output the model’s maker did not want it to produce. Prompt injection targets an application: the instructions and data a developer wrapped around the model. A system can resist jailbreaks well and still be open to injection, because the injected instruction may ask for something perfectly ordinary, such as forwarding a document.
What an attacker gains
- Hidden context. System prompts, tool definitions and business rules that reveal how the application works.
- Data. Other users’ information, internal documents reached through retrieval, or secrets placed in the prompt.
- Actions. Anything the assistant’s tools can do, carried out with the assistant’s permissions.
- Trust. Output the user believes because it came from an assistant they rely on, such as a false summary or a link.
Real cases
Prompt injection is not theoretical. These three were found by security researchers, reported to the vendors and written up publicly.
- Bing Chat, 2023. A research team led by Kai Greshake showed that instructions hidden in web pages could take over Bing’s GPT-4 chat when it read them, and coined the term indirect prompt injection. Their paper described data theft and manipulation of what the assistant told the user. Source: Greshake et al., 2023.
- Microsoft 365 Copilot, 2024. Johann Rehberger showed a chain in which a shared document carried hidden instructions, Copilot then searched the user’s emails and documents, and the data was packed into a link using invisible characters. If the user clicked it, the data went to the attacker. It was reported in January 2024 and Microsoft fixed it. Source: The Hacker News, August 2024.
- ChatGPT memory, 2024. Rehberger also showed that untrusted content, such as a document or web page the assistant was asked to read, could plant false long-term memories about the user. Those memories then shaped every later conversation, and a follow-up demonstration used the same route to send conversations to an outside server. Source: Schneier on Security, October 2024.
The pattern is the same each time: the assistant read something its user did not write, treated it as an instruction, and had access to something worth taking.
How to test for prompt injection
Test only systems you own or have written permission to test. A sound test follows the data, not a list of clever phrases.
- Map every input the model reads. User messages are the obvious one. Then list retrieved documents, web content, file uploads, tool results, memory and anything another system writes into the prompt.
- Map what the model can do. List each tool, what it can reach, and whose permissions it runs with.
- Decide what counts as a failure. For example: the assistant reveals its instructions, returns another customer’s data, or calls a tool the user did not ask for.
- Test each input against each failure. Check whether text arriving through that input can change the model’s behaviour.
- Record evidence. Keep the input, the output and the tool calls, so a developer can reproduce the result.
- Retest after every change. Model updates and prompt edits change behaviour in both directions.
Our AI and LLM hacking course walks through this method day by day.
Defences that hold up
No single control stops prompt injection. The aim is to make sure that when an injection succeeds, it achieves little.
| Defence | What it does | Its limit |
|---|---|---|
| Least privilege for tools | The assistant can only do what the task needs, with the user’s own permissions | Needs careful design of every tool |
| Human approval for risky actions | Sending, paying, deleting and sharing need a person to confirm | People approve without reading if asked too often |
| Separating trusted and untrusted content | Fetched content is marked as data and handled by a restricted step | Reduces risk; the model can still be influenced |
| Output handling | Model output is validated before it reaches a browser, database or shell | Protects downstream systems, not the conversation |
| Input and output filters | Catch known attack patterns and data leaving the system | Attackers rephrase; filters alone are not enough |
| Keeping secrets out of prompts | Nothing in the context is worth stealing | Requires moving checks into code |
| Logging and monitoring | Unusual tool use and repeated probing are noticed | Detects; does not prevent |
The rule that follows from all of these: never let the model be the only thing standing between an attacker and something valuable. Permission checks belong in code.
Frequently asked questions
Can prompt injection be fully fixed?
Not with current models. It can be reduced and contained. Design the system so that a successful injection has little it can reach.
Is prompt injection the same as SQL injection?
The idea is similar, since both mix instructions with data. SQL injection has a complete fix in parameterised queries. Prompt injection has no equivalent, because a language model has no strict boundary between the two.
Does a stronger system prompt stop it?
It helps a little and fails often. Instructions in a system prompt are still text the model weighs against other text.
Who needs to learn this?
Anyone building, testing or approving an application that puts a language model in front of users or data: developers, security testers, product owners and architects.
Where can I practise legally?
On systems built for it. The SecurityElites labs run against live models and are free to start. When you are ready to prove the skill, the SE-ARTCP certification tests it hands-on.
