Implementation Guide

Preventing Prompt Injection Data Exfiltration via Markdown Links and Images in Enterprise AI Applications and Agents

Treat Markdown rendering as an egress channel for untrusted output, not as a model-alignment problem. Close it with layered controls: 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, and log and enforce policy at runtime. No single control is sufficient, so each layer should cover the limits of the others.

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.

Attack chain stages and the control that breaks each
StageControl that breaks it
Injection ingressTreat retrieved content and tool output as untrusted.
Sensitive data in contextApply least-privilege retrieval and keep secrets out of prompts.
Output generationParse and filter URLs in model output.
Client renderingDisable or restrict remote image and link rendering.
Network egressEnforce CSP and deny-by-default egress.

The layered approach

  1. Stop the client from fetching arbitrary remote images.
  2. Allowlist and rewrite URLs in model output.
  3. Enforce CSP and network egress limits.
  4. Keep sensitive data out of model context.
  5. 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.

Review your Markdown egress controls

If you are assessing runtime policy enforcement, least-privilege access, and audit logging for AI agents, speak with Trussed AI about how those controls apply to your architecture.

Talk to an Expert