Skip to content
tezvyn:
Menu

Direct versus indirect injection and agent defenses

Source: interviewMediumHow cards are made

Summary

agent security under injection.

Key points

direct injection comes from the user prompt; indirect hides in third-party data the agent ingests like web pages.

What's really being asked

The interviewer wants to see that you understand why autonomous, tool-using agents dramatically raise injection risk, especially via untrusted external content, and that you can design layered, least-privilege defenses rather than a single filter.

The full answer

The distinction: direct prompt injection is when the attacker is the user, typing instructions that try to override the system prompt. Indirect prompt injection is when malicious instructions are planted in third-party data the agent consumes, a web page it browses, a document it retrieves, an email it reads, or an API response, so the agent encounters the payload as ordinary content and may execute it, even though the human user is innocent. Indirect injection is especially dangerous for agents because they can take real-world actions through tools. Multi-layered defense: first, treat all fetched and retrieved content as untrusted, delimit and label it clearly as data, and run injection detectors and content sanitization before it enters the prompt. Second, apply least privilege to tools and APIs, scope credentials narrowly, restrict which actions are callable in a given context, and avoid giving the agent broad write or financial capabilities by default. Third, require explicit human confirmation for high-impact or irreversible actions like sending money, deleting data, or emailing externally. Fourth, monitor and log all tool calls and outputs, add anomaly detection and rate limits, and run output guardrails. Defense in depth means no single bypass is catastrophic.

The mistakes people make

Addressing only direct injection and trusting browsed or retrieved content. Relying on a single system-prompt instruction to ignore injections. Granting the agent broad tool permissions and no human-in-the-loop. Assuming output filtering alone protects against malicious actions.

What usually comes next

Why is indirect injection worse for agents, it triggers real actions. How does least privilege limit blast radius. When require human confirmation. How do you detect anomalous tool sequences.

A concrete example

An agent summarizing a web page hits hidden text saying transfer funds using the payment API. With untrusted-content labeling, a scoped read-only tool set, and human confirmation gating any payment, the injected instruction is contained instead of executed.

Interview question

Why does indirect prompt injection pose a greater risk to a tool-using web-browsing agent than to a plain chatbot?

  • a.Indirect injection only affects chatbots without any tools
  • b.The agent ingests untrusted external content as instructions and can then trigger real-world actions through its toolsCorrect
  • c.The agent's user is always the attacker in indirect injection
  • d.Tools make the model immune to injected instructions
Why?

Indirect injection plants instructions in fetched data, and an agent with tools can act on them, e.g. calling a payment API. The user is innocent in indirect injection, and tools increase, not remove, the risk.

Just read this? Test yourself on what you have been reading.

Read the original → cheatsheetseries.owasp.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles