๐ What Is It?
Prompt Injection occurs when attacker-controlled text causes an LLM to ignore its intended instructions and follow the attacker's instead. The model receives system prompt, chat, retrieved documents, and tool output as one undifferentiated token stream and has no built-in way to tell "instructions to obey" from "data to process." It is a trust-boundary failure, not a bad-word filter problem โ and it is the entry point for most serious LLM attacks.
โ ๏ธ Top Attack Vectors
- Instruction override: "Ignore all previous instructions..."
- Role-play / DAN jailbreak: alternate persona "with no rules"
- System-prompt extraction: "Repeat everything above verbatim"
- Encoding / obfuscation: base64, ROT13, homoglyphs to dodge filters
- Indirect (RAG/web/email): hidden instructions in content the model reads โ zero-click
- Tool / function-call hijacking: steer the agent into real actions
- Multi-modal: instructions in image text, alt-text, or metadata
๐ญ Direct vs. Indirect
Direct: the user is the attacker โ jailbreak or leak the prompt. Blast radius is their own session.
Indirect (second-order): the user is the victim. Payload is planted in a page, RAG doc, email, tool result, or image; a normal question over poisoned data triggers it with the victim's privileges. This is the high-impact, modern class for any app with retrieval or agency.
๐ด Attack Flow
โ
2. OVERRIDE: make the model treat it as authoritative
โ
3. ACT: leak data, produce disallowed output, or call a tool
โ
4. EXFIL/EFFECT: render a tracking image, send email, complete a transaction
โ Vulnerable Code
โ Secure Code
โ Prevention Checklist
- Delimit & mark all untrusted content as data (sanitised/nonce fences)
- Keep secrets, keys, and internal URLs OUT of the system prompt
- Screen user AND retrieved/tool content with an injection guardrail
- Least-privilege, per-session, schema-validated tools; authz in code
- Human-in-the-loop for sensitive/irreversible actions (out-of-band)
- Treat model output as untrusted; sanitise before render/execute
- Network egress allow-list to block data exfiltration
- Separate "reader" (untrusted) from "executor" (privileged) roles
- Full-chain logging, rate limits, and an injection regression suite
๐งฐ Tools & Takeaway
You cannot "prompt your way out" of prompt injection. Prompt-level defences lower how often it succeeds; architectural defences (least privilege, human approval, egress control) limit the impact when it succeeds anyway. Assume the model will be hijacked and build so it still can't read what it shouldn't, act without approval, or send data anywhere.