← All articles

Prompt Injection Explained: The Security Hole in Every AI App, and How to Limit It

· 6 min read

Prompt Injection Explained: The Security Hole in Every AI App, and How to Limit It

This guide is for business owners, developers and team leads who use or build AI assistants and want to understand prompt injection in plain terms. You will learn what it is, how it shows up in everyday tools, and which defences are worth putting in place first. It explains defence only and gives no attack recipes.

What prompt injection is

Prompt injection is a weakness in applications built on large language models (LLMs). According to the OWASP LLM Prompt Injection Prevention Cheat Sheet, it lets an attacker change the model's behaviour by slipping in input that alters its intended output. The root cause, in OWASP's words, is a common design in which natural language instructions and data are processed together without a clear separation.

A normal program keeps code and data apart. An AI model reads one stream of text. Your instructions, the customer's message and a web page the AI just fetched all arrive as words. The model has no built-in way to know which words are orders and which are material to read.

OWASP lists the impacts: bypassing safety controls, unauthorised data access, leaking the system prompt, unauthorised actions through connected tools, and manipulation that persists across sessions.

Direct and indirect injection

OWASP separates two main forms.

- **Direct injection:** the attacker types the instruction into the AI themselves, for example into a support chatbot, asking it to ignore its rules. - **Indirect (remote) injection:** the instruction is hidden in content the AI processes later. OWASP names code comments, commit messages, issue descriptions, reviews, web pages, documents and emails as places this can sit.

Indirect injection matters most for businesses. You may never see the attacker's text. Your assistant reads an email, a PDF or a web page, and the hidden words go in with it. The cheat sheet points to research on GitLab Duo as an original case study of this kind of remote injection.

Where it gets worse: AI that can act

A chatbot that only answers questions can say something wrong. An assistant with tools can do something wrong. OWASP describes agent-specific attacks where the model is tricked into calling tools with attacker-controlled parameters. If your assistant can send email, read files, query a database or make payments, the damage of one successful injection grows with every permission you gave it.

We cover how those connections work in our guide to [what MCP is](https://encoderbytes.com/Blog/what-is-mcp-model-context-protocol-guide), and the wider threat picture in our article on [AI cyber security threats for small businesses](https://encoderbytes.com/Blog/top-5-ai-cyber-security-threats-small-business-defence).

Why filters alone do not work

The obvious fix is to block phrases such as "ignore all previous instructions". OWASP says this is not a security boundary. Attackers can reword an instruction in many ways that a deny list does not match, and the cheat sheet lists Base64 and hex encoding, invisible characters, scrambled spellings, and attacks in other languages or scripts.

The language point matters in Pakistan and the Gulf. OWASP cites studies showing that unsafe inputs translated into low-resource languages bypassed GPT-4's safeguards far more often than the English originals, and that Arabic written in Latin letters produced unsafe output from some models. It adds that these studies tested the models, not an application's own filters. The lesson is to test your own setup in every language your users write, including Urdu and Roman Urdu, and not to assume English-only tests cover you.

OWASP's overall position, as summarised in its LLM01 guidance, is that fool-proof prevention is not known. The aim is to reduce risk with layers.

Six layers that limit prompt injection: least privilege, human approval, separating data, checking outputs, logging, and regular testing
Six layers drawn from OWASP's cheat sheet. None is enough alone.

Six defences to put in place

1. **Least privilege.** Give the AI the minimum access it needs. OWASP recommends read-only database accounts where possible and restricted API scopes. If the assistant only needs to read orders, do not give it an account that can edit them. 2. **Human approval for risky actions.** Require a person to approve consequential actions such as sending, paying, deleting or publishing. OWASP warns about user fatigue: if people approve everything without looking, the control stops working. Show the exact action and its details. 3. **Keep trusted and untrusted text apart.** Label retrieved documents, tool results and web pages as data. OWASP notes that labels alone are not an enforcement boundary, so do not rely on wording like "treat this as data". 4. **Treat model output as untrusted.** Check it before it reaches another system, as you would any outside input. Use safe rendering for web output and parameterised queries for databases. 5. **Log and alert.** Record tool calls and security decisions, leaving out passwords and unneeded sensitive content. Watch for unusual tool use. 6. **Test regularly.** Try injection attempts against your own app, in every language you support, with dummy data and sandboxed tools.

How to test your own app with promptfoo

Promptfoo is an open-source (MIT licence) command-line tool for evaluating and red-teaming LLM apps. Its documentation says it can scan for more than 50 vulnerability types, including jailbreaks, injections and RAG poisoning. The documented start is:

- Run "npx promptfoo@latest redteam setup", which opens a web page where you describe your app, choose a target and pick plugins and strategies. - Save the configuration as promptfooconfig.yaml, then run "npx promptfoo@latest redteam run". - View results with "npx promptfoo@latest redteam report".

The documentation notes that the scanner runs on your own machine, so it can reach any endpoint your machine can reach. Point it at a test copy of your app, not your live system with real customer data.

Mistakes to avoid

- Relying on a "never obey user instructions" line in the system prompt as your only defence. - Giving an assistant your main admin login "to make it work". - Letting an assistant read untrusted email or web pages and send messages in the same step without approval. - Testing in English only. - Treating a clean test run as proof of safety. OWASP calls its own sample tests a smoke test, not a benchmark.

What to do this week

List every tool and data source your AI assistant can reach. For each, ask what the worst outcome would be if a hidden instruction took control. Remove access you do not need, add an approval step for anything irreversible, and run one promptfoo scan on a test copy. If your team needs help, our AI team can review an existing assistant or build one with these controls in place.

Sources

OWASP LLM Prompt Injection Prevention Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html OWASP GenAI Security Project, LLM01:2025 Prompt Injection: https://genai.owasp.org/llmrisk/llm01-prompt-injection/ Promptfoo repository (MIT licence): https://github.com/promptfoo/promptfoo Promptfoo red teaming quickstart: https://github.com/promptfoo/promptfoo/blob/main/site/docs/red-team/quickstart.md

Frequently asked questions

What is prompt injection in simple terms?

It is when text given to an AI, by a user or hidden in a document or web page, changes what the AI does. It works because the model reads instructions and data as one stream of text.

What is the difference between direct and indirect prompt injection?

In direct injection the attacker types the instruction to the AI. In indirect injection it is hidden in content the AI reads later, such as an email, web page or document.

Can prompt injection be fully prevented?

OWASP's guidance says fool-proof prevention is not known. It recommends layered controls such as least privilege, human approval, output checks, monitoring and regular testing.

How can I test my AI app for prompt injection?

Use an open-source red-teaming tool such as promptfoo against a test copy of your app, with dummy data. Repeat the tests in every language your users write.

Contact

Let's Discuss Your Project

Tell us what you are building. Every conversation is covered by a mutual NDA.

What happens next

  1. 1Our team contacts you within one business day
  2. 2An initial discussion to understand your requirements
  3. 3A scope assessment and proposal

We reply from info@encoderbytes.com.