// Concept and defense
XSS in AI-built SaaS
What XSS is
XSS (Cross-Site Scripting) is when an attacker manages to inject a script into your page, and that script runs in other users’ browsers with their session. With XSS, the attacker steals cookies/tokens, acts as the victim, alters the screen and captures what they type. It is one of the oldest flaws and still one of the most common, because it only takes one place where user input becomes HTML without being escaped.
The root is always the same: data that came from outside (a comment, a name, a profile field, a URL parameter) is rendered as HTML/JS instead of plain text.
Where AI introduces XSS
An AI assistant generates XSS easily when it chooses to render dynamic HTML without escaping. The most common patterns:
- dangerouslySetInnerHTML (React) or v-html (Vue) with user-supplied content.
- Building HTML by string concatenation with unescaped input.
- Reflecting a URL parameter straight into the page (reflected XSS).
- Saving a user field and displaying it later without escaping (stored XSS, the worst).
- innerHTML on the client with unsanitized API data.
How to prevent it
The core defense is escape by default: treat all external data as text, not HTML. Modern frameworks (React, etc.) escape by default; XSS enters precisely when you bypass that. A strong CSP is the second layer, limiting the damage even if a script gets through.
- Let the framework escape; avoid dangerouslySetInnerHTML/v-html with user data.
- If you must render third-party HTML, sanitize it with a tested library (allowlist).
- A strict Content Security Policy (CSP) as a second layer of defense.
- An HttpOnly session cookie, so the script cannot read it.
Where RET fits
The Promptbook guides you to hunt the spots where input becomes HTML without escaping, the pattern AI repeats most. When the product displays user-generated content (a comment, a profile, a team name), Risk Review reviews those flows and the CSP before a stored XSS becomes mass session theft.
Want to know whether this happens in your system?
Manual pentest for web applications, APIs and apps, from R$9,500, with the Sprint run within 7 business days. We refund 50% if we find no flaw.
Frequently asked questions
Doesn’t React protect me from XSS automatically?
React escapes by default when you render text in JSX, which covers most cases. XSS enters when you bypass that, mainly with dangerouslySetInnerHTML on user-supplied content. That is where the protection is lost.
Which XSS is the worst?
Stored XSS: the malicious script is saved (in a comment, a profile) and runs in the browser of everyone who sees that content. A single poorly escaped field can compromise many users.
Does CSP replace escaping input?
No. Escaping input is the primary defense; CSP is the second layer, limiting the damage if a script gets through. Use both: escaping prevents, CSP contains.
How do I test it?
Insert a simple test payload into a field that is displayed later and see whether it executes instead of appearing as text. If it executes, it is XSS. The Promptbook guides that check on the spots that render HTML.