Prompt injection

Prompt injection is an attack on an application built on a large language model (LLM). The attacker supplies text that the model treats as an instruction, so the model follows it instead of the developer's. It works because the model receives instructions and data as one stream of text and does not reliably keep them apart. It takes two forms, direct prompt injection and indirect prompt injection. OWASP lists it as LLM01 in its Top 10 for LLM Applications. Most attacks listed under web attacks reach a server, a database or a browser; this one reaches a model.

Section Web attacks Updated Standard OWASP LLM01:2025

Quick facts

Prompt injection: quick facts
ItemDetail
TargetAn application that passes text to an LLM: a chat assistant, a summariser, an agent with tools
OWASP categoryLLM01:2025 Prompt Injection (the OWASP list for LLM applications, not the web Top 10)
TypesDirect prompt injection (the user's own input) and indirect prompt injection (external content the model processes)
Root causeInstructions and untrusted data reach the model as one stream of text
Possible outcomesDisclosure of data, or actions taken with the application's tool permissions
Main defenceLayered controls, starting with limits on what the model can reach and do
Does a WAF stop it?No claim. A request filter sees the HTTP request, not what the model does with the text

Definitions follow OWASP's LLM01 entry on genai.owasp.org.

How prompt injection works

An application built on a large language model assembles a prompt: the developer's system prompt, then the user's message, and sometimes documents or other external content. The model replies to the whole text. Prompt injection exploits that. If the user's part tells the model to disregard its system prompt, the model may comply, because nothing in the text marks one part as more trusted than another.

This differs from classical injection. SQL or shell injection breaks out of a data slot into a command language with a strict grammar, and parameterised calls keep code and data apart there. Natural language offers no equivalent of a parameterised call, and OWASP writes that it is unclear whether fool-proof methods of prevention exist.

In generative AI applications the same mechanism applies wherever text reaches the model. This page uses "prompt injection" for the attack on an LLM application; "AI prompt injection" and "LLM prompt injection" point at the same attack.

Direct prompt injection

In a direct prompt injection the attacker is the user. They type instructions into the application's own input to change how the large language model behaves: to expose its system prompt, to slip past its restrictions or to get output the developer did not intend. How much harm follows depends on what the application lets the model do. A chat that only produces text can embarrass its owner; one connected to internal data or tools can do more.

Indirect prompt injection

In an indirect prompt injection the instructions arrive inside external content the model is asked to process: a web page, an email, a shared document, a search result, a tool response. OWASP describes the case as a large language model accepting input from external sources such as websites or files. The user may be innocent and may not see the hidden text. When an assistant summarises a page or reads a mailbox, it also reads whatever an attacker managed to place there.

How an indirect prompt injection attack occurs

An indirect prompt injection attack occurs in four steps:

  1. Someone places instructions in content the model will later read: a web page, an email, a file.
  2. A user or the application asks the model to process that content, for example to summarise it.
  3. The model receives the hidden instructions in the same text, with nothing to mark them as less trusted.
  4. If the model has tools, it can act on them with the permissions the application gave it.

This form matters more as applications give models more sources and more tools. Each source is another place an instruction can come from, and each tool widens what an obeyed instruction can do.

Prompt injection examples

These prompt injection examples are attack scenarios that OWASP lists for LLM01. Each targets the model, not the web server.

  • Direct prompt injection: an attacker types into a customer support chatbot an instruction to ignore its previous guidelines and query private data.
  • Indirect prompt injection: a user asks an assistant to summarise a web page that contains hidden instructions.
  • Resume prompt injection: an attacker uploads a resume with split malicious prompts, and the model that evaluates the candidate is steered by the combined text.
  • Obfuscated prompt injection: the instructions are written in several languages or encoded, for example in Base64 or emojis, to evade filters.

These are illustrations of the mechanism, not a measure of how common each case is.

What it can lead to

OWASP's description of the impact of prompt injection (LLM01) includes:

  • disclosure of confidential information, including details of the system prompt;
  • unauthorised access to functions available to the model;
  • content manipulation that produces incorrect or biased output;
  • execution of arbitrary commands in connected systems.

These outcomes can occur without any flaw in the web server. The application does what it was built to do, on instructions it should not have followed. Least privilege and human approval, covered below, limit how far such an instruction can reach.

What a WAF can and cannot see

A WAF sits in front of a site and examines HTTP requests. Bridge WAF has three modes (off, monitor and block), per-domain rate limiting and an activity log of flagged requests. This page makes no claim that any of them stops prompt injection.

The limits come from where a filter stands. An attack written in ordinary sentences has no fixed pattern a rule can reliably match, unlike a command separator. Indirect injection may not pass through the protected site's request at all: the text can sit in a document the model fetches from somewhere else. And a request filter observes the HTTP request, not the model's output or the actions the model takes afterwards. At the edge of an LLM application a filter can still do a narrow job: rate limiting can slow repeated calls to a model endpoint from one client, which reduces abuse volume and does nothing about injection itself.

For what a filter covers in general, see web application firewall, and monitor mode for how flagged requests are observed before anything is blocked.

How to reduce the risk

Prompt injection defense is a set of layers, not one filter. OWASP writes that it is unclear whether fool-proof methods of prevention exist, so this page does not promise to prevent prompt injection outright. The measures OWASP lists mitigate the impact; prompt injection prevention in practice means limiting what an obeyed instruction can do, because prompt injection risk depends on what the model can reach.

Give the model least privilege. Connect only the tools and data the task needs, with the narrowest permissions, so an obeyed instruction can do little.

Require human approval for high-risk actions. Sending, deleting, paying and sharing should need a decision made outside the model.

Separate and label external content. Mark text from outside as data and treat everything the model reads from outside as untrusted.

Constrain and check output. Fix the expected format and validate it before use. Model output passed unchecked to a shell or a database can turn the problem into command injection or a relative of it.

Test adversarially, and keep logs. OWASP lists adversarial testing and attack simulations among the measures. Prompt injection testing means trying crafted inputs against the application in a controlled setting, which is what OWASP's adversarial testing and attack simulations describe. Logging model inputs, outputs and tool calls makes misuse visible afterwards.

For attacks that target the server rather than the model, start from web attacks.

Questions

What is prompt injection?

Prompt injection is an attack in which text supplied to a language model is interpreted as an instruction, making the model act against the developer's intent. OWASP lists it as LLM01 for LLM applications.

What is the difference between direct and indirect prompt injection?

In a direct injection the user types the malicious instructions. In an indirect injection they are hidden in content the model processes, such as a web page, an email or a document.

How does an indirect prompt injection attack occur?

An indirect prompt injection attack occurs when instructions hidden in external content, such as a web page, an email or a file, are read by the model along with the rest of its text. The model does not reliably tell them apart from the developer's instructions, so it may follow them.

Can prompt injection be fully prevented?

OWASP writes that it is unclear whether fool-proof methods of prevention exist. Defences are layered: least privilege for the model, human approval for high-risk actions, treating external content as untrusted, and output checks.

Does a WAF protect against prompt injection?

This site makes no such claim. A WAF examines HTTP requests; prompt injection depends on how a model interprets text and what actions it can take.