Insecure output handling means a site shows text written by an AI model without checking it first. If that text contains HTML, a Markdown link or a URL, the browser can treat it as code. The result is cross-site scripting (XSS) or data leaking to another site.
Our post on the Drupal AI module advisories of October 28 showed this in practice. Five of the eight fixes were XSS, and the Critical one came from Markdown links. That post covered what to update. This one asks why model output is untrusted input, and what the fix looks like in WordPress and Drupal code.
The short version: treat every AI answer like a comment from an anonymous visitor. Escape it as plain text when you can. When you need formatting, run it through a small allowlist of tags. Check every link’s scheme. Configure your Markdown converter for untrusted input. Then add a Content Security Policy as the backup.
What insecure output handling means
The name comes from OWASP, the open security project behind the well-known Top 10 lists. Version 1.1 of its Top 10 for Large Language Model Applications lists "LLM02: Insecure Output Handling" as a risk. The summary line reads, "Neglecting to validate LLM outputs may lead to downstream security exploits."
The current 2025 list keeps the idea under a new name. OWASP’s LLM05:2025 Improper Output Handling page defines it as poor validation, sanitization and handling of model outputs. Both names describe the same mistake. We use the older one because developers still search for it.
OWASP explains why it matters. Prompt input can control what the model writes. That, it says, "is similar to providing users indirect access" to whatever the output touches. Anyone who can shape the prompt can shape what your page prints.
Why the model is not a trusted author
It is easy to think of a model as part of your own code. But the model’s words come from its input, and much of that input is not yours.
A visitor types a question. A summarizer reads a web page. A chatbot pulls in a pasted support article. Any of these can carry instructions the model follows. Our explainer on prompt injection covers how direct and indirect injection work. One of OWASP’s LLM05 attack scenarios is a web page with hidden instructions. They tell the model to capture sensitive content and send it out.
So the model sits in the same place as a form field. OWASP’s first fix is to "Treat the model as any other user, adopting a zero-trust approach" when handling its output. On a CMS, the closest match is an anonymous commenter. You would never give a commenter the Full HTML text format. AI output deserves the same limit.
Three ways AI output turns into an attack on a CMS page
Most AI features return HTML, Markdown or URLs. Each has its own failure.
| Output type | What can go wrong | WordPress fix | Drupal fix |
|---|---|---|---|
| HTML | Script tags, event handler attributes or HTMX-style attributes reach the page | esc_html(), or wp_kses() with a short allowlist |
#plain_text, or Xss::filter() or a restricted text format |
| Markdown | Raw HTML passes through the converter; links use javascript: |
Converter set to escape or strip HTML, then wp_kses() |
Converter set to escape or strip HTML, then a restricted text format |
| URLs and images | Script links, or image URLs that send data to an outside server | esc_url() with a protocol list |
UrlHelper::stripDangerousProtocols() |
HTML. If a feature prints model HTML as is, every tag the model writes reaches the page. That includes tags an attacker talked it into writing.
Markdown. OWASP’s own example is Markdown or JavaScript that the model writes and the browser runs. Markdown looks like plain text. But converters turn links and raw HTML into real HTML.
URLs and images. A javascript: link runs script when clicked. An image needs no click at all. Say injected text gets the model to write an image whose URL holds private data. The browser sends that data when the page loads. The parent post’s SA-CONTRIB-2026-268 was about this kind of link leak.
Fixing insecure output handling in WordPress
WordPress already has the tools. The work is using them on AI output every time. The WordPress escaping guide says to escape "as late as possible, ideally as data is being outputted" to the page. So escape in the template, not when you save the answer.
Plain text first. If the answer needs no formatting, print it with esc_html(). That removes the risk for that field.
A short allowlist for formatting. The guide says to use wp_kses() "to safely escape for all non-trusted HTML" on a page. Pass it a small array: paragraphs, lists, strong, em, code and a with only href. Skip wp_kses_post() for AI output. It allows all post content HTML, far more than a chatbot answer needs.
Check every link. The wp_kses() reference says its default protocol list leaves out javascript:. It adds that javascript "should not be allowed for untrusted users" at all. For links you build yourself, esc_url() takes a protocol list. Its function reference says it returns an empty string for any other protocol. Passing array( 'https' ) is a sound default for AI output.
The same rules apply to the client in our WordPress 7.1 AI client post. It returns model text. What your theme or plugin does next decides whether you have insecure output handling.
Fixing insecure output handling in Drupal
Drupal escapes by default in more places, which helps. The gaps show up where developers step around those defaults.
Twig. Drupal’s guide to writing secure code says Twig now "auto escapes everything by default" in templates. It warns that the raw filter does not escape output. Never print AI output with |raw.
Render arrays. The Render API overview says #plain_text holds text that needs to be escaped. That is the right key for most AI answers. The #markup key goes through Xss::filterAdmin() instead. Drupal’s API docs call that "a very permissive XSS/HTML filter for admin-only use" in their summary. AI output is not admin input, so keep it out of #markup.
Filtered HTML. When you need some tags, the secure code guide points to Xss::filter(). You can also render the answer through the restricted text format anonymous users get. For links, the guide names UrlHelper::stripDangerousProtocols() and UrlHelper::filterBadProtocol().
Drupal 10 reaches end of life on December 9, 2026. After that date, Drupal 10 core gets no more security fixes, including fixes to the filters above. See our Drupal 10 end-of-life guide and our plain-language guide to the Webform advisories for what to check now.
Your Markdown converter needs its own settings
Many AI features convert Markdown before any filter runs, so the converter’s defaults matter. The PHP library league/commonmark is a common choice. Its security page says raw HTML input is left unescaped by default. Unsafe links are allowed by default too, to match the CommonMark spec.
The fix is two settings. Set html_input to escape or strip, and set allow_unsafe_links to false. The library counts javascript:, vbscript:, file: and most data: links as unsafe. Then run the HTML through wp_kses() or Xss::filter() anyway.
If your front end renders Markdown in JavaScript, the same question applies to that library. Our post on the HTML Sanitizer API covers the browser-side option for inserting HTML safely.
Content Security Policy is the backup
Filters can miss. A Content Security Policy (CSP) limits what injected script can do when they do. MDN’s XSS guide calls CSP "a backup defense" for when the first defense fails. OWASP’s LLM05 page also recommends a strict CSP for model-generated content.
MDN’s CSP guide recommends a strict policy based on nonces or hashes. It is clear about the limit: a CSP "is not an alternative to sanitizing input" on its own. A policy can run in report-only mode first, so you see what would break.
For the image leak above, an img-src rule that lists only your own hosts blocks images from anywhere else.
Where the standards stand as of November 2026
These details can change, so check them before you quote them.
- OWASP’s current list is the 2025 edition, where this risk is LLM05:2025. The owasp.org project page still shows the version 1.1 name and points to genai.owasp.org for the latest list.
- The Drupal AI module fixes from October 28 ship in AI 1.5.2 and 1.4.11, per the parent post.
- Drupal 10 reaches end of life on December 9, 2026.
A checklist for any AI feature on your site
Run these checks on every plugin, module or custom feature that shows model output:
- Find every place AI text is printed. Search templates for the variables that hold answers, summaries and generated fields.
- Default to plain text.
esc_html()in WordPress,#plain_textor Twig autoescape in Drupal. - Allowlist when you need formatting.
wp_kses()with a short list, orXss::filter()or a restricted text format. Never Full HTML,wp_kses_post(),#markupor|rawfor AI text. - Lock down links. Allow
httpsonly. Stripjavascript:anddata:links. - Configure the Markdown converter to escape or strip HTML and block unsafe links.
- Limit outside images with a CSP
img-srcrule. - Add a strict CSP, starting in report-only mode.
- Test with hostile input. Ask your feature to write a script tag and a
javascript:link. Confirm neither works.
None of these checks depend on which model you use. They stop insecure output handling even when an injection gets through.
Frequently Asked Questions
What is insecure output handling?
It is OWASP’s term for using AI model output without validating, sanitizing or encoding it first. When a site shows that output as HTML or Markdown, it can carry script or leak data. OWASP listed it as LLM02 in version 1.1 of its Top 10 for LLM Applications.
Is insecure output handling the same as improper output handling?
Yes, in practice. OWASP renamed the risk Improper Output Handling in its 2025 list, where it is LLM05:2025. The description and fixes are the same idea.
Why is AI output untrusted if my own code asked for it?
Because the model’s answer depends on its input, and that input often comes from visitors, web pages or documents. Anyone who can shape the input can shape the output, so OWASP says to treat the model like any other user.
Is Markdown output safer than HTML?
Not by default. Many converters pass raw HTML through and allow javascript: links unless you change their settings.
Which WordPress function should I use for AI answers?
Use esc_html() when the answer can be plain text. Use wp_kses() with a short allowlist when you need formatting, and esc_url() with an https-only protocol list for links.
Is #markup safe for AI output in Drupal?
No. Drupal passes #markup through Xss::filterAdmin(), which its API docs describe as a very permissive filter for admin-only use. Use #plain_text, Xss::filter() or a restricted text format instead.
Does a Content Security Policy fix insecure output handling?
It reduces the damage but does not replace filtering. MDN calls CSP a backup defense and says it is not an alternative to sanitizing input. Use both.
How can AI output leak data without a click?
Through images. If a model is steered into writing an image whose URL holds private data, the browser requests that URL when the page loads. A CSP img-src rule and link filtering block this.
Does a model that resists prompt injection remove the risk?
No. Resistance lowers the odds, but no model blocks every injection. Output filtering works no matter what the model writes.