Prompt Injection Explained: Attacks, Defences and Testing

Prompt injection explained: direct and indirect attacks, why OWASP ranks it LLM01, the defences that limit damage, and safe testing for developers.

By Galactic News Editorial · Published 2026-11-17T13:47:13+00:00 · Updated 2026-11-17T13:47:13+00:00

Prompt injection explained with direct and indirect attack types

Prompt Injection Explained: Attacks, Defences and Testing

Prompt injection is the top-ranked risk in the OWASP Top 10 for LLM Applications, listed as LLM01 in the 2025 edition. It happens when untrusted text makes a language model follow an attacker's instructions instead of its owner's. This guide explains how the attack works, the two main forms it takes, and the defences and tests that limit the damage.

The core problem is structural. A language model reads instructions and data through the same channel, a stream of tokens. It cannot reliably tell "here is content to analyse" apart from "here is a command to obey". OWASP notes that it is unclear whether fool-proof prevention exists.

Prompt Injection Explained: Direct vs Indirect Attacks

Direct injection comes from the person using the app. They type a hostile instruction into the chat, such as asking the model to ignore its rules or reveal its system prompt. It is the easiest form to demonstrate and usually the least dangerous, because the attacker can mostly only harm their own session.

Indirect injection is more dangerous. The attacker plants instructions in content the model will read later: a web page, a PDF, an email, a database row, a review or a tool result. The victim is a different user, and the attacker needs no access to the app at all.

A typical indirect attack looks like this. An assistant summarises a vendor email that contains a hidden line telling it to include the contents of the last five messages in its reply. The model follows the hidden line because it reads it as part of its input.

TypeWhere the payload entersWho is harmedTypical goal
DirectThe user's own messageThe userBypass rules or reveal configuration
IndirectA web page, email, file or tool resultA different userLeak data, plant false answers, trigger actions
MultimodalText hidden in an imageThe user or a third partySame goals, delivered through vision input

OWASP also notes that attacks can be multimodal. Text hidden in an image can be enough to steer a model that reads images.

Why Prompt Injection Is So Hard to Stop

Prompt injection has held the top spot in the OWASP LLM Top 10 for two consecutive editions. The reason is that the flaw is not a bug in one model or one app. It is a property of how language models read text.

Filtering does not fix it. Attackers rephrase payloads, split them across lines, translate them or hide them in formats the filter does not check. A filter that blocks one wording misses the next.

The UK National Cyber Security Centre wrote in December 2025 that prompt injection may never be fully mitigated the way SQL injection can be. NIST guidance takes the same position: current mitigations do not offer full protection, so systems should be designed on the assumption that injection succeeds whenever a model reads untrusted input.

Defences That Limit the Damage

Since the injection itself cannot be fully prevented, the defences that work are architectural. They limit what a successful injection can do.

Least privilege for tools. Give the model only the tools and data the task needs. An assistant that reads tickets should not be able to delete them. A fetch tool needs a strict host allow-list and must block private network ranges, including the cloud metadata address 169.254.169.254.

No secrets in the prompt. API keys, internal URLs and other users' data never enter the instructions or the context. The provider key stays in server secrets.

Human approval for consequential actions. Sending email, moving money, deleting records and changing access should require a person to confirm. This is the control that stops an injection from becoming a breach.

Treat model output as untrusted input. Validate, escape and type-check anything the model returns before it reaches a database, a shell, a browser or another API. Never pass model output into an eval, a shell command or a SQL string without sanitisation.

Separate untrusted content. Mark external content as data and tell the model to ignore instructions inside it. Route untrusted sources through a model with fewer permissions or a narrow interface.

Log and monitor. Record prompts, responses, tool calls and API calls. A run of failed tool calls can be the first sign of an attack.

Researcher Simon Willison calls the dangerous combination the "lethal trifecta": an agent with private data access, exposure to untrusted content and a way to communicate externally. Remove any one of the three and the attack loses its power.

How to Test for Prompt Injection

Testing proves whether an injected instruction actually changes behaviour. The goal is to detect the injection, not to cause harm.

Follow these six steps:

  1. Map the input channels. List everything the agent reads that a third party can influence: emails, attachments, web pages, files, database rows and tool results.
  2. List the tools and their rights. Note what each tool can read, write or send.
  3. Write test payloads. Cover direct and indirect vectors, several phrasings, system-prompt extraction and tool-call hijacking with inert arguments.
  4. Feed the payloads through each channel, one at a time.
  5. Observe the real effects. Measure the action taken or the data that leaves the system, not just the words in the reply.
  6. Replay at scale. Run the suite on every change to prompts, tools or model versions.

Use a canary token for safe testing. The probe asks the model to repeat a unique, meaningless word. If the word appears in the output, the injection succeeded, and nothing of value changed.

Benchmarks such as AgentDojo and InjecAgent measure how often indirect injections succeed against tool-equipped agents. They show that even recent models remain vulnerable in a meaningful share of scenarios. That is why testing should run continuously, not once at launch.

Bottom Line

Prompt injection is OWASP LLM01 because it is easy to try and hard to stamp out. No prompt wording fully prevents it. The practical answer is architecture: narrow tool permissions, no secrets in prompts, human approval for consequential actions, output treated as untrusted, and continuous testing with canary tokens. Assume some injections will succeed, and build the system so that a successful one cannot do much damage.