A Comment Became Code: Stored XSS in an AI-Built App, Measured in a Real Browser

The backend accepted it, the page rendered it, and in a real browser it read the signed-in person's session token out of local storage. One line of rendering was the whole difference.

A comment containing an image tag with an error handler was accepted by the backend and, when the page rendered the comment list the way generated code does, ran in a real browser and read the signed-in person's session token out of local storage, while the same comment rendered as text appeared as the characters the visitor typed and validation on the way in refused it without refusing an ordinary comment containing a less-than sign

Someone types a comment. Your app stores it, and later shows it to somebody else. That is the entire feature, and it is the entire vulnerability.

Text becomes code at the moment something decides to interpret it, and in a web app that decision is one line in the part that draws the list. Nothing about the storing is wrong; the question is what the next browser is told the characters are.

So we stored a comment that is markup, opened the page in a real browser, and read the resulting page back out to see what it had done.

Watch it instead

Injection is number 7 in our countdown of the security holes that turn up most often in apps built with AI.

Video: 31,000 AI-Built Apps Scanned: The 10 Security Holes That Actually Get You Hacked.
Watch it instead 31,000 AI-Built Apps Scanned: The 10 Security Holes That Actually Get You Hacked.
From the Back4app channel. This guide is the long version of its seventh position. Open on YouTube →

What did the browser actually do with it?

Ran it, and handed over a session. Here is the same stored comment, rendered two ways on the same page:

The same stored comment rendered two ways in a real browser: assigned with innerHTML it ran and printed the session token taken from local storage, and assigned with textContent it appeared as the characters the visitor typed, while a server-side guard refused the markup comment and still accepted an ordinary comment containing a less-than sign

The backend accepted the comment in both cases. It is not a storage problem, and no permission was misconfigured — this is what happens when a working app shows one person’s words to another.

How we measured: one Parse Server 7.4.0 backend in Docker, a page served locally, opened in headless Chrome, with the resulting DOM read back to see whether the payload executed. Identical across two clean runs — the lab is in the repo.

What was in the comment?

An image that does not load, and the handler every image already has. That is all:

<img src=x onerror="...">

There is no exploit kit here and nothing exotic. src=x is guaranteed to fail, onerror is a standard attribute, and the browser is doing precisely what the specification says. The payload is two features of HTML used together.

the backend accepted the comment:             yes
after the page rendered it:                   session token taken: r:a-real-looking-session-token
the same comment in the text-rendered list:   shown as the characters the person typed

The browser did nothing wrong. It was handed markup and it rendered markup, which is its entire job.

The token matters because of where front-end SDKs keep it. Local storage is readable by anything running on the page, which is why “it only runs in the visitor’s browser” is not the reassurance it sounds like.

Which line decided it?

The one that puts the comment on the page. This is what an assistant writes when you ask it to show a list:

// Stack: browser JavaScript | File: page/index.html — the version that runs it
document.getElementById('as-generated').innerHTML =
  rows.map((c) => `<div class="c">${c.body}</div>`).join('');

And this is the same list, built as text:

// Stack: browser JavaScript | File: page/index.html — the version that shows it
for (const c of rows) {
  const d = document.createElement('div');
  d.textContent = c.body;
  safe.append(d);
}

The second one is longer, which is most of why the first one gets written. A template string is the obvious way to turn a list into HTML, and it is obvious right up until one of the values came from a stranger.

Should the server refuse it too?

Yes, and that is the part generated apps never have. Escaping on display protects the screen you remembered. A rule on the way in protects the export, the e-mail template, and the screen somebody writes next year:

// Stack: Parse Server 7.4.0 | File: cloud/main.js
Parse.Cloud.beforeSave('Comment', (req) => {
  const body = String(req.object.get('body') ?? '');
  if (/<[a-z!\/]/i.test(body)) throw new Parse.Error(142, 'comments are text, not markup');
});
the same comment, posted again:               refused — comments are text, not markup
an ordinary comment with a < in it:           accepted

That second line is the one to copy. The rule looks for a less-than sign immediately followed by a letter, a slash or a bang — the shape of a tag — so 3 < 5 passes. A filter that bans the character itself would make your app unusable for anyone discussing numbers.

One stored comment, rendered twice
session takenwith innerHTML, in a real browser
→
just textwith textContent, same comment, same page
1line of HTML in the comment: an image whose source does not load
Measured on Parse Server 7.4.0 with MongoDB 7, Docker 29.4.3 and headless Chrome, 29 October 2026. Execution read back from the DOM. Identical across two clean runs.

Where does prompt injection fit?

It is the same shape with a different interpreter. Text arrives as data, something decides to read it as instructions, and the instructions run with whatever authority that something has.

The difference worth internalising is that you cannot escape your way out of the second one. There is no textContent for a language model: the instructions and the data are the same channel by design, and filtering wording is a losing game against a person who can rephrase.

So the useful question stops being “will it be fooled” and becomes “what can it reach when it is”. That is a permissions question, and it is the subject of the next post in this series rather than something a validation rule solves.

When is rendering user markup the right call?

When markup is the feature, and plenty of products need it. A rich text editor, a documentation tool, a comment system that supports formatting — all of these exist to let people produce markup, and refusing tags outright would be refusing the product.

The answer there is not escaping but a sanitiser: a library that parses the input, keeps an allowlist of tags and attributes, and drops everything else. Bold and links in, event handlers and script tags out.

What never works is writing that sanitiser yourself with a regular expression. The list of ways to express the same tag is long, actively researched, and not the thing your product competes on — and this is one of the few places where “use a library” is simply correct.

What should you type into your own app today?

Post a comment on your own app containing <img src=x onerror="alert(1)">. Use a test account, on your own staging copy, as the product’s ordinary user.

Then open that page as somebody else. If you get an alert box, you have the answer, and you got it in the same thirty seconds it would have taken anybody else.

If nothing happens, check the row in your database anyway. A comment stored as markup and escaped on one screen is a comment waiting for the second screen that forgets.

Tagssecurityxssinjectionvalidationcloud-codevibe-coding

Frequently asked questions

What is stored XSS and how would I know if my app has it?

It is when something a person typed is later rendered as markup rather than text, so their input runs in somebody else's browser. We stored a comment containing an image tag, opened the page in a real browser, and the comment read the signed-in visitor's session token out of local storage.

Is innerHTML dangerous in a React or plain JavaScript app?

Whenever the value came from a person, yes. The same comment assigned with innerHTML ran, and assigned with textContent appeared as the characters that were typed. Those two lines were the entire difference, and the generated version used the first one.

Does escaping on display make validating on input unnecessary?

It makes it survivable, not unnecessary. Escaping protects the one place you remembered; validating on the way in protects every place that reads the row afterwards, including an export, an e-mail template and a screen written six months later by somebody else.

How do I validate input without breaking ordinary text?

Reject the shape of markup rather than individual characters. Our server-side guard refused a comment containing a tag and accepted nice one, 3 < 5 though, because a less-than sign followed by a space is not an opening tag. A filter that bans the character itself breaks your product for anyone writing about numbers.

Can an attacker steal a session with cross-site scripting?

That is normally the point. Front-end SDKs keep the session token in local storage so the app can resume it, and anything running on that page can read it. In our run the injected comment printed the token straight onto the page, which is one line away from sending it somewhere.

Is prompt injection the same problem as XSS?

It is the same shape with a different interpreter: text that was supposed to be data gets treated as instructions. The defence is the same too — decide what the untrusted text is allowed to reach before worrying about what it says, which is a question about permissions rather than wording.

Further reading

Reviewed & verified by Back4app Engineering, Editorial review at Back4app

Tested Oct 29, 2026 — Local: Docker 29.4.3 on macOS, arm64 · Parse Server 7.4.0 with MongoDB 7 · Chrome headless · Node 22.21.1, no dependencies.

More from Back4app Engineering

Backend · tutorial

Your Frontend Talks Straight to the Database. Here Is How to Lock It Down [Full Repo]

Backend · error-guide

Why Does the API Return 101, 119, 142 or 209? Every Backend Error Code, Reproduced [Full Repo]

Backend · tutorial

How to Ban and Unban Users in Your App, and Make the Ban Stick [Full Repo]