Direct and Indirect Prompt Injection
A user or retrieved document supplies language that the model may confuse with authority; the robust defense is to constrain capabilities and decisions outside it.
Frame the problem
Security starts with a concrete asset, attacker capability and trust crossing.
Why the system fails
The system assumes a prompt can permanently order the model to ignore malicious instructions while still exposing sensitive context and powerful tools.
The important question is not “what is Direct and Indirect Prompt Injection?” but “which assumption let untrusted data or an over-scoped identity cross untrusted language → model instruction-following behavior?” Trace the decision at the boundary, then constrain what can happen after the first control fails.
Design the control in layers
Start with the control closest to the interpretation or privilege boundary: Treat all external content as untrusted data Then add a control that reduces blast radius and telemetry that proves the decision was enforced.
The resulting design is not labelled secure. Record the identified controls, the known failure paths, the remaining exposure, and the evidence you would need during an incident.
| Prevent | Detect | Recover |
|---|---|---|
| Treat all external content as untrusted data · Keep secrets out of unnecessary context · Authorize each tool action deterministically and require approval when high risk | Policy-denied tool requests and action/context provenance | Contain the affected identity or component, scope impact from audit evidence, and preserve a regression test. |
Key points
- Asset: Agent goals, private context and any reachable tool capability.
- Boundary: Untrusted language → model instruction-following behavior
- Primary control: Treat all external content as untrusted data
- Detection signal: Policy-denied tool requests and action/context provenance
- Always ask what limits damage when the primary control fails.
Prompt Injection Attack Path
Change the system and observe which assumption moves.
- 01Valid loginThe attacker starts as an ordinary customer.
- 02 · TRUST CROSSINGChange resource IDA client-controlled identifier selects another record.
- 03Authentication passesThe cookie is valid; identity is known.
- 04 · TRUST CROSSINGOwnership check missingThe API loads by id without tenant/owner scope.
- 05Sensitive data returnedA valid 200 response makes the breach quiet.
Follow the attack
Safe conceptual simulation: capability → missing control → crossed boundary → asset impact.
- 1Attacker starts with: A direct user or author of external content retrieved by the agent.
- 2The system assumes a prompt can permanently order the model to ignore malicious instructions while still exposing sensitive context and powerful tools.
- 3The weak or missing boundary control is crossed: Untrusted language → model instruction-following behavior
- 4Impact: Tool misuse, data disclosure or task hijacking.
- Tool misuse, data disclosure or task hijacking.
Defend, detect, recover
One prevention is a single point of security failure. Layer it and make failure observable.
- • Treat all external content as untrusted data
- • Keep secrets out of unnecessary context
- • Authorize each tool action deterministically and require approval when high risk
- • Policy-denied tool requests and action/context provenance
- • Contain the affected identity or component.
- • Scope access from audit evidence.
- • Fix the boundary and add a regression test.
- • Misconfiguration and new access paths can bypass the intended control.
- • A privileged insider or compromised control plane may still reach the asset.