Engineering & Cloud

Prompt Injection Attacks: Risks and Defences

Prompt injection attacks explained: direct vs indirect, real examples, why AI agents raise the risk, and a defence checklist for LLM features.

Illustrative image: a security engineer examining a printed document next to a laptop showing a chat assistant

Prompt injection attacks trick a large language model (LLM) into following instructions an attacker wrote instead of the ones you gave it. The text can come from the user or hide inside a web page, email or document the model reads. There is no complete fix, so the defence is to limit what a fooled model can do.

If your web app has an LLM feature that reads content you do not control and can call tools, this is the security risk to design for first. This guide ends with a defence checklist your team can apply before launch.

What is prompt injection?

An LLM receives one stream of text: your system prompt, the user’s message, and any content you add, such as a retrieved document or a web page. It has no reliable way to tell which parts are instructions and which parts are data. Prompt injection exploits that.

The OWASP Top 10 for LLM Applications 2025 lists prompt injection first, as LLM01:2025, and defines it as user prompts that change the model’s behaviour or output in ways the developer did not intend.

The UK National Cyber Security Centre (NCSC) explains why this is hard. In its post Prompt injection is not SQL injection (it may be worse), published on 8 December 2025, it notes that SQL injection was solved by separating data from instructions, for example with parameterised queries. An LLM has no such boundary. It predicts the next token from everything in its context.

Illustrative image: two security colleagues reviewing an alert on a large monitor
Treat every document an AI reads as untrusted input.

Types of prompt injection attacks

OWASP describes two main types.

Direct prompt injection. The user types instructions that override yours: “ignore your previous instructions and…”. In a chat feature, the attacker is the person at the keyboard. The usual goals are to leak the system prompt or misuse a tool the chat can call.

Indirect prompt injection. The instructions sit in content the model processes on behalf of a normal user: a web page, an email, a PDF, a support ticket or text in an image. The user does nothing wrong. They ask the assistant to “summarise this page” or “triage my inbox”, and the hidden text takes over. Microsoft’s Security Response Center describes how such text can be hidden from people, for example as white-on-white text or non-printing Unicode characters.

For a product team, indirect injection is the bigger risk. You can rate-limit and moderate your own users, but you cannot review every web page, email or file your feature will read.

Prompt injection vs jailbreak

OWASP treats jailbreaking as a form of prompt injection: the goal is to make the model ignore its safety rules, for example to produce harmful content. Prompt injection is broader: the attacker wants your model to do something useful to them inside your application, such as reading another customer’s data or calling an API.

The practical difference: a jailbreak is mainly the model vendor’s problem. Prompt injection in your product is your problem, because it is your data and your tools.

Prompt injection examples

Indirect prompt injection in an agentic browser (2025). Brave’s security team reported that Perplexity’s Comet browser passed page content to its model without separating it from the user’s request. When a user asked Comet to summarise a page, instructions hidden in that page could be treated as commands, and the agent acted with the user’s logged-in browser sessions. Brave says it reported the issue on 25 July 2025 and published on 20 August 2025. An update to the post says later testing found the class of attack was not fully mitigated, and Brave reported it again. Brave’s point for builders: an agent acting with the user’s sessions sidesteps protections such as same-origin policy.

Data exfiltration through a rendered image. Microsoft describes an attack where injected instructions make the model output a markdown image whose URL points to an attacker’s server, with the user’s data encoded in the URL. When the chat interface renders the image, the browser requests it automatically. The data leaves without a single click. Microsoft says it now blocks this technique deterministically.

The second example matters for every web app, not only agents. If your chat UI renders model output as markdown or HTML, the output is an exfiltration channel.

Why prompt injection attacks matter more with AI agents

A chatbot that only answers questions can be embarrassed by prompt injection. An agent can be used. The risk grows with three properties, and it is highest when one feature has all three:

  1. It reads untrusted content: web pages, inbound email, uploaded files, third-party API responses, retrieved documents.
  2. It has access to private data: customer records, the user’s mailbox, internal documents.
  3. It can act or send data out: call APIs, send messages, write to a database, fetch URLs, or render links and images.

Many AI features shipping now combine all three: support assistants that read tickets and update the CRM, browser agents, and coding assistants with shell access. Protocols such as the Model Context Protocol make it easy to connect a model to many tools at once, which also makes it easy to give it far more access than the task needs. If you are still deciding how much autonomy to give, our explainer on AI agents vs agentic AI covers the trade-off, and our guide to agentic AI security maps the wider agent risks to controls.

Why there is no complete fix

The main sources agree, and you should plan for it:

  • OWASP states it is unclear whether fool-proof methods of prevention exist, and adds that RAG and fine-tuning do not fully mitigate the risk.
  • The NCSC writes that prompt injection attacks “may never be totally mitigated” the way SQL injection was. It treats the problem as a confused deputy and advises reducing likelihood and impact instead of expecting a product to solve it.
  • Anthropic, in its 24 November 2025 research post on browser use, calls prompt injection “far from a solved problem”. With its improved safeguards, its own adaptive attacker still succeeded in 1.4% of attempts against Claude Opus 4.5 in the browser setting it tested, and Anthropic notes that even a 1% rate is a meaningful risk.

Better models and classifiers lower the success rate. They do not take it to zero. So treat model behaviour as untrusted and put your real controls in ordinary code.

How to prevent prompt injection: a defence checklist

Use this checklist for any LLM feature in a web app. It follows the guidance from OWASP, the NCSC, Microsoft and Brave, ordered by impact.

Layer What to do Why it works
Permissions Give the model’s tools the minimum scope; run them with the end user’s permissions, never an admin service account A fooled model can only do what its credentials allow
Side effects Require explicit user confirmation for anything that sends, pays, deletes, shares or changes permissions The user sees the real action before it happens
Untrusted input Mark external content clearly (delimiters or tags) and keep it apart from your instructions Makes attacks harder; it does not stop them
Output handling Treat model output as untrusted input: encode it, block external images and links by default, validate structured output against a schema Closes exfiltration channels and stops injected output reaching your database or shell
Data access Retrieve only the data the current user may see; scope retrieval by tenant and role in code Injection cannot leak what the model never received
Monitoring Log prompts, retrieved sources, tool calls and outputs; alert on unusual or failed tool calls You can detect and investigate an attack
Testing Keep a set of injection test cases and run it before every release Catches regressions when prompts, tools or models change

The checklist

  • List every source of text the model reads, and mark which ones an outsider can write to.
  • For each tool, write down the worst thing it could do if the model were fully controlled by an attacker. If that is unacceptable, reduce the tool’s scope or add a confirmation step.
  • Enforce authorisation in your API, not in the prompt. “Only show the user their own orders” in a system prompt is a request, not a control.
  • Split risky flows: a model that reads untrusted content should not hold write tools in the same step. Pass only structured, validated fields to the step that acts.
  • Show the user what will happen (“Send this email to these 3 people?”) with the real parameters, not the model’s summary of them.
  • Render model output as plain text or a sanitised markdown subset. Allow images and links only from domains you control.
  • Do not rely on deny-lists of attack phrases. The NCSC warns attackers simply rephrase.
  • Add rate limits and spending caps on tool calls so one bad session cannot do unlimited damage.
  • Log enough to reconstruct a session, while following your GDPR data-minimisation rules for what you store.
  • Write injection test cases for your own features: hidden instructions in a test email, an uploaded document and a web page your agent reads. Assert that no unconfirmed side effect happens.
  • Record prompt injection as a known residual risk with an owner, as the NCSC recommends, and review it when you add a new tool or data source.

FAQ

Can prompt injection be fully prevented?

No. As of October 2026 there is no known complete fix, as OWASP, the NCSC and Anthropic all state. You reduce the likelihood with input separation and better models, and you limit the impact with permissions, confirmations and output controls.

What is indirect prompt injection?

It is when attack instructions arrive through content the model reads for a normal user, such as a web page, email or document, rather than from the person typing. It is the main risk for agents and assistants that browse or read inboxes.

Does RAG stop prompt injection?

No. Retrieval adds more external text to the context, so a poisoned document becomes a new way in. OWASP says RAG and fine-tuning do not fully mitigate the risk.

Next step

Before your next AI release, draw the feature on one page: what the model reads, what data it can see, and what it can do. Then go through the checklist above for every tool.

We build LLM features into web apps with permissions, confirmation flows, output handling and tests from the first release. See our web app development service, or our AI integration service if the model work is the main job. If you want a second opinion on an AI feature before launch, send us a short description of what it reads and what it can do.

Keep reading

Get new guides in your inbox

One practical email when we publish something worth your time. No spam; unsubscribe with one click.