LogicTrail
  • Trails
  • Check my app
  • Pricing
  • Sign in
  1. Trails
  2. /
  3. Working with your AI agent
  4. · 4 minutes · Pro

The chatbot that wrote hidden code

Your app lets users share AI chat conversations. Everyone who opened one shared chat got signed out, and their sessions were used elsewhere.

This answers: Can AI chatbot replies cause XSS? No coding needed. 2 quick decisions.

  • Supervising your AI
  • Keys and secrets

Checking your access…

Can AI chatbot replies cause XSS?

Yes. A user can persuade the model to output HTML with hidden code, such as an image tag with an onerror handler, and if your page inserts replies as raw HTML, that code runs for everyone who views the conversation. Treat model output as untrusted: render it as text, or Markdown first.

Trail of the bug
  1. Stranger
  2. AI provider
  3. Browser

Breaks at Browser: Model output rendered as raw HTML

Why AI tools write this bug

Chat interfaces often render Markdown by converting it to HTML and inserting it directly, which is safe for trusted text and dangerous for anything a user can influence.

How to fix it

  1. Search for dangerouslySetInnerHTML and similar.

3 more steps, and a prompt that checks your own app for this bug. Part of Pro.

Unlock

Common questions

Can I tell the model not to output HTML?
You can, but users can tell it otherwise. The page must be safe regardless.

Related scenarios

  • The agent that reset productionFree · 5 min
  • The key you deletedPro · 4 min
  • The key you pasted into chatPro · 4 min

More on this trail

Working with your AI agent: Dangerous commands, fix loops, deleted tests, prompt injection and invented packages.

Want someone to look?

We check AI-built apps for this and three other common leaks, in plain English.

Check my app
Sign in

Sign in to walk this one

2 decisions, about 4 minutes, and a prompt to check your own app for the same problem.

Sign in No password. We email you a link.

How to fix it

  1. Search for dangerouslySetInnerHTML and similar.

3 more steps, and a prompt that checks your own app for this bug. Part of Pro.

Unlock