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.
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
- Search for dangerouslySetInnerHTML and similar.
3 more steps, and a prompt that checks your own app for this bug. Part of Pro.
UnlockCommon questions
- Can I tell the model not to output HTML?
- You can, but users can tell it otherwise. The page must be safe regardless.