How Markdown link and image exfiltration works
Markdown rendering is an egress channel for untrusted output. When an injected instruction causes a model to emit a Markdown image or link whose URL carries data from its context, a client that renders the output can send that data to a destination the attacker controls. Because the channel sits in rendering and network paths rather than in the model, it is closed with layered controls, not with model alignment.
| Stage | Control that breaks it |
|---|---|
| Injection ingress | Treat retrieved content and tool output as untrusted. |
| Sensitive data in context | Apply least-privilege retrieval and keep secrets out of prompts. |
| Output generation | Parse and filter URLs in model output. |
| Client rendering | Disable or restrict remote image and link rendering. |
| Network egress | Enforce CSP and deny-by-default egress. |
The layered approach
- Stop the client from fetching arbitrary remote images.
- Allowlist and rewrite URLs in model output.
- Enforce CSP and network egress limits.
- Keep sensitive data out of model context.
- Log and enforce policy at runtime.
Implement rendering restrictions and output filtering
These controls act on the model output and on the client that renders it.
- Restrict client rendering. Disable or restrict remote image and link rendering so the client does not fetch arbitrary remote images.
- Filter model output. Parse and filter URLs in model output, then allowlist and rewrite them before they reach the client.
- Test allowlist rules against bypasses. Check lookalike hostnames, userinfo in the URL, unusual ports, mixed case, and redirects on allowed hosts.
- Preserve legitimate Markdown. Tables, code blocks, approved images, and links to approved domains should still render.
Add CSP, egress restrictions, and least-privilege data access
These controls limit what a rendered response can reach, and what data is available to leak in the first place.
- Content Security Policy. Enforce CSP so the client cannot load resources from arbitrary destinations.
- Network egress. Enforce network egress limits with a deny-by-default posture.
- Least-privilege retrieval. Apply least-privilege retrieval so the model only has access to the data a task requires.
- Prompt hygiene. Keep secrets and other sensitive data out of prompts and model context.
Enforce policy and log at the runtime layer
Runtime enforcement covers cases the earlier layers miss, and logging makes blocked attempts visible. Each blocked or rewritten URL should produce a log entry with the following fields:
- The session
- The URL
- The rule that applied
- The source content
Define indicators for the activity you want to detect, and configure alerts to fire on them.
Verify the controls with red-team tests
- Plant an injection in a retrieved document that asks for an image URL containing a canary string from context. Confirm no request reaches a test endpoint you control.
- Repeat with inline links, reference-style links and images, raw HTML in Markdown, and encoded or split canary data.
- Test allowlist bypasses: lookalike hostnames, userinfo in the URL, unusual ports, mixed case, and redirects on allowed hosts.
- Run every test on every surface: web chat, embedded copilots, agent consoles, chat integrations, and link preview services.
- Confirm each blocked or rewritten URL produces a log entry with the session, URL, rule, and source content, and that alerts fire on the indicators you defined.
- Confirm legitimate Markdown still renders: tables, code blocks, approved images, and links to approved domains.