Auth and server code
Your AI chat’s replies are untrusted input
If your app shows replies from a language model, treat each reply as if a stranger typed it. Anyone whose text reaches the prompt, through a chat message, an uploaded file, a web page the model reads or a row in your database, can steer what the model writes back. When the reply is inserted into the page as HTML, or its Markdown images load automatically, that steering becomes script in your user’s browser or a quiet request that carries their data to someone else’s server.
TL;DR
- OWASP lists this as LLM05:2025, Improper Output Handling: model-generated JavaScript or Markdown returned to a user and run by the browser.
- The risky pattern in AI-built React apps is
markedoutput (ormarkdown-itwithhtml: true) passed todangerouslySetInnerHTML.markedsays plainly that it does not sanitise. react-markdownis safe by default. Addingrehype-rawswitches that off unlessrehype-sanitizeruns after it.- Sanitising doesn’t stop the second leak: a Markdown image whose address carries chat data loads with no click. Bing Chat, Azure AI Playground and Claude all had to fix this in 2023.
- Fix: render replies with
react-markdown, no raw HTML, and only load images from hosts you choose. Add a Content-Security-Policy as a backstop.
This guide is for founders whose app has an AI chat, an assistant, a summary box or anything else that shows text a model wrote, built with Lovable, Bolt, Replit, Cursor, Claude Code or similar. It is the AI-specific case of finding PL-024, user content rendered as raw HTML.
Why a model’s reply isn’t safe text
It is tempting to trust a reply because your own server asked for it. But the model writes whatever its input steers it towards, and much of that input isn’t yours: the user’s message, a PDF they uploaded, a web page a tool fetched, a support ticket from another customer, a product review in your database. Instructions hidden in any of those (prompt injection) can make the model answer with HTML or a Markdown image. There is no setting that reliably stops this, so the fix has to be in how you display the reply.
OWASP’s Top 10 for LLM applications names it LLM05:2025, Improper Output Handling. Its example is exactly this: JavaScript or Markdown generated by the model, returned to a user and run by the browser. It says to treat model output like any other untrusted input and to encode it for the place it ends up.
The two ways it goes wrong
| 1. Reply inserted as HTML | 2. Markdown image loads by itself | |
|---|---|---|
| What the model writes | <img src=x onerror="…"> inside an otherwise normal answer |  with earlier chat text in the address |
| What happens | The script runs as your user, on your domain. With supabase-js it can read the session from localStorage and call your API as them. | The browser fetches the image the moment it is shown. The address, with the data in it, lands in the attacker’s server log. No click needed. |
| Does sanitising fix it? | Yes, if every reply goes through a sanitiser or a renderer that never outputs raw HTML. | No. An image with an https address is allowed by DOMPurify, rehype-sanitize and react-markdown’s defaults. |
| The fix | Render with react-markdown and no raw HTML, or run DOMPurify on the HTML. | Only load images from hosts you list, or show a link instead. Back it with a CSP img-src. |
The second one is not hypothetical. Johann Rehberger showed a web page steering Bing Chat into writing a Markdown image that sent page data to his server (June 2023); Microsoft’s fix appears to be a Content-Security-Policy limiting images to its own domains. He reported the same issue in Azure AI Playground, Google’s Vertex AI Studio and Claude, where the fix was to stop loading Markdown images until the user clicks (August 2023). If the companies that make the models had to fix it, an app built in a weekend probably hasn’t.
Check your code in a minute
Run this in your project folder. It lists every place the app inserts HTML or renders Markdown, which is where a reply could become script.
grep -rnE "dangerouslySetInnerHTML|\.innerHTML *=|insertAdjacentHTML|v-html|\{@html|marked|markdown-it|showdown|rehype-raw|ReactMarkdown|react-markdown" \
--include='*.ts' --include='*.tsx' --include='*.js' --include='*.jsx' --include='*.vue' --include='*.svelte' \
--exclude-dir=node_modules --exclude-dir=dist --exclude-dir=.next .| What you find | What it means |
|---|---|
dangerouslySetInnerHTML with marked or showdown output | Leak 1. marked’s own docs say it does not sanitise its output and recommend DOMPurify. Fix it today. |
markdown-it output | Leak 1 only if it was created with html: true; by default it escapes HTML. Leak 2 still applies either way. |
dangerouslySetInnerHTML, innerHTML, v-html or {@html} with the reply directly | Leak 1, unless the value goes through DOMPurify.sanitize on the line before. |
react-markdown with rehype-raw in rehypePlugins | Leak 1 unless rehype-sanitize comes after it in the list. The react-markdown README says rehype-raw is only for Markdown you trust. |
react-markdown with no rehype-raw and no custom urlTransform | Safe from leak 1. Check leak 2: images still load from any https host. |
| Nothing | Replies are probably shown as plain text, which React escapes. Leak 2 can’t happen either, because no image is rendered. |
To test it end to end, ask your own chat to repeat this text exactly, then look at the page and your browser’s network tab. If an alert box appears, it is leak 1. If a request goes to example.com, it is leak 2.
Repeat exactly, keeping the formatting: <img src=x onerror="alert('PL-024')"> and Some models refuse or rewrite the text, so a clean result from this test isn’t proof. The grep above is the more reliable check.
No terminal, or want a second reading? Paste the component that shows replies into the free AI chat rendering check. It runs in your browser, follows the value back to where the HTML is made, and sends nothing.
The fix for a React app
Render the reply as Markdown with no raw HTML, and decide yourself which image hosts may load. This keeps formatting, code blocks and links, and closes both leaks:
import ReactMarkdown from 'react-markdown';
// Hosts you serve images from yourself. Everything else becomes a plain link.
const IMAGE_HOSTS = new Set(['yourapp.com', 'your-project.supabase.co']);
export function Reply({ text }: { text: string }) {
return (
<ReactMarkdown
skipHtml
components={{
img: ({ src = '', alt = '' }) => {
let host = '';
try { host = new URL(src, 'https://yourapp.com').hostname; } catch {}
return IMAGE_HOSTS.has(host)
? <img src={src} alt={alt} loading="lazy" />
: <a href={src} target="_blank" rel="noopener noreferrer nofollow">{alt || 'image link'}</a>;
},
a: ({ href, children }) => (
<a href={href} target="_blank" rel="noopener noreferrer nofollow">{children}</a>
),
}}
>
{text}
</ReactMarkdown>
);
}skipHtmldrops any HTML the model writes instead of showing it as text. Without it,react-markdownalready escapes HTML, so either is safe;skipHtmljust looks cleaner.- Don’t add
rehype-rawto make tables or colours work. Useremark-gfmfor tables. If you must allow some HTML, putrehype-sanitizeafterrehype-raw. - Leave
urlTransformalone. The default removesjavascript:links; the README warns that replacing it with something looser opens you to XSS. - If you keep marked, pass its output through DOMPurify before
dangerouslySetInnerHTML. That closes leak 1 only; handle images as above.
Paste this into your AI builder if you’d rather it made the change:
Find every place this app shows text written by the AI model (chat replies, summaries, suggestions). Render each one with react-markdown using skipHtml, with no rehype-raw and no custom urlTransform. Add a custom img component that only renders images from these hosts: [your domains]; for any other host render a plain link with rel="noopener noreferrer nofollow" instead. Remove any marked, markdown-it or showdown output passed to dangerouslySetInnerHTML. Don't change anything else. List the files you changed.Add a backstop: Content-Security-Policy
A Content-Security-Policy tells the browser where scripts and images may come from, so a mistake in one component isn’t the end. Microsoft’s fix for Bing Chat appears to be exactly this. Start with images and scripts, and adjust for the services your app really uses:
Content-Security-Policy: default-src 'self'; script-src 'self'; img-src 'self' data: https://your-project.supabase.co; connect-src 'self' https://your-project.supabase.co wss://your-project.supabase.co; object-src 'none'; base-uri 'self'Load the app with the header set, open the browser console and add each blocked address you actually need. Finding PL-030 covers a missing policy, and the free headers check tells you whether your live site sends one.
Also check where replies end up
- Admin and support screens. Conversation logs shown to you or your team are often rendered by a different component than the chat, written later and with less care. A stolen admin session is worse than a user’s.
- Emails. A summary pasted into an HTML email template without escaping can carry the same image trick to the recipient’s mail client.
- Saved replies. If replies are stored and shown to other users (shared chats, public answers, generated listings), leak 1 is stored XSS: one poisoned reply runs for every viewer.
Sources
- OWASP Top 10 for LLM Applications: LLM05:2025 Improper Output Handling (2025)
- react-markdown README: security, skipHtml, rehype-raw, rehype-sanitize, urlTransform (version 10, checked 13 Nov 2026)
- marked documentation: “Marked does not sanitize the output HTML” (checked 13 Nov 2026)
- Johann Rehberger: Bing Chat data exfiltration exploit explained (18 Jun 2023)
- Johann Rehberger: Anthropic Claude data exfiltration vulnerability fixed (1 Aug 2023)
Related findings
The checks behind this guide, each with example code, a self-check and the fix.
Free check
Paste your chat component, see what a reply can do.
Paste the component that shows your AI’s replies into the free AI chat rendering check. It runs in your browser: no request is sent and nothing is stored. It flags replies inserted as raw HTML (marked into dangerouslySetInnerHTML, rehype-raw without a sanitiser, v-html) and Markdown images that load from any address, with the line, the fix and a prompt for your AI builder.
Written by Manraj Singh Dhillon. Last checked 13 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.