Prompt Injection in LLM Apps
By Malcolm McDonald Founder, Editor-in-ChiefAuthor of Grokking Web Application Security
Prompt injection represents an easy way for an attacker to introduce unexpected behavior in a machine learning model.
- Prevalence
- Common
- Exploitability
- Easy
- Impact
- Harmful
What is prompt injection?
Prompt injection is an injection attack against applications built on large language models. The attacker places instructions in text the model reads, either typed directly or hidden in documents and web pages, so that the model ignores its system prompt. It can leak secrets, expose the system prompt, or trigger actions the application's authors never intended.
What you'll learn
- How direct and indirect prompt injection override a system prompt
- Why context manipulation and jailbreaking work against LLM apps
- How least privilege, structured prompting and output filtering limit the damage
Where this lesson counts
OWASP Top 10 for LLMs
Crafted input overrides the instructions a model was given, hijacking its behaviour and output.
Learn more about LLM01Confidential instructions embedded in the system prompt are extracted by users.
The lab extracts the hidden system prompt on the way to hijacking the model.
Learn more about LLM07This lesson includes
Prompt Injection in LLM Apps lab
Watch scripted chats demonstrate direct injection, context manipulation, indirect injection and jailbreaking. Then try it yourself on an order support chatbot: tell it to ignore its previous instructions and get it to reveal the database URL.
How to prevent Prompt Injection in LLM Apps
The prevention guide covers six approaches, including:
- Implement Least Privilege Design
- Input Sanitization
- Structured Prompting
Prompt Injection in LLM Apps quiz
Four questions. Passing marks the lesson complete.
Sources
- Prompt Injection OWASP
Related lessons
Browse all 45 lessons
Sensitive Information Disclosure in LLMs
Your machine learning model may be leaking sensitive data without you knowing it.
Misinformation and Model Poisoning in LLMs
Machine learning is prone to bias and unreliability, and you need to put in safeguards to protect against that.
Slopsquatting (LLM Supply Chain)
When LLM tools hallucinate package names, attackers can register malicious packages with those names.
SQL Injection
If you are vulnerable to SQL Injection, attackers can run arbitrary commands against your database.